线性布局问题
我的应用程序布局有一个奇怪的问题。 我有一个列表视图,其中我为每个项目插入了自己的布局。 这很好用。
以下是插入的 XML 布局的一部分:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/label"
android:paddingTop="2px"
android:paddingLeft="15px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp" />
<TextView
android:id="@+id/price"
android:paddingTop="2px"
android:paddingLeft="15px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:id="@+id/days"
android:paddingTop="2px"
android:paddingLeft="15px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:id="@+id/test"
android:paddingTop="2px"
android:paddingLeft="15px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:id="@+id/status"
android:paddingTop="2px"
android:paddingLeft="15px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
</LinearLayout>
在我的活动中,我正在执行以下操作:
tv = (TextView) row.findViewById(R.id.price);
tv.setText(getString(R.string.wishlist_price) + ": " + "293.99€");
getString(R.string.wishlist_price) 在 string.xml 中定义为“Price”
现在奇怪的是: 对于上面的“293.99€”,手机上的输出如下所示:
Price: 293.99€
但是,如果我更改货币,例如更改为 22.95€,则输出如下所示:
Price:
22.95€
因此,它会在“Price:”之后添加换行符 我无法找出是什么原因造成的。
我用“2.99€”尝试过,它给出了预期的输出:
Price: 2.99€
有人知道是什么导致了示例“22.95€”中的换行符吗?
编辑: 围绕上面的线性布局有两个线性布局。也许它们会导致这种奇怪的行为:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:id="@+id/product_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
I have a weired problem with the layout of my app.
I have a listview, in which I have inserted an own layout for each item.
This works nice.
Here is a part of the inserted XML layout:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/label"
android:paddingTop="2px"
android:paddingLeft="15px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp" />
<TextView
android:id="@+id/price"
android:paddingTop="2px"
android:paddingLeft="15px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:id="@+id/days"
android:paddingTop="2px"
android:paddingLeft="15px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:id="@+id/test"
android:paddingTop="2px"
android:paddingLeft="15px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:id="@+id/status"
android:paddingTop="2px"
android:paddingLeft="15px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
</LinearLayout>
In my activity I am doing following:
tv = (TextView) row.findViewById(R.id.price);
tv.setText(getString(R.string.wishlist_price) + ": " + "293.99€");
getString(R.string.wishlist_price) is defined in string.xml as "Price"
Now the strange thing:
For the above "293.99€" the output on the phone looks like this:
Price: 293.99€
But if I change the money, for example to 22.95€, the output looks like this:
Price:
22.95€
So it does a newline after "Price:"
I cant found out what is causing this.
I tried it with "2.99€", it gives the intended output:
Price: 2.99€
Does someone has an idea what is causing the newline in the example "22.95€"?
EDIT:
There are two linearlayout around the one above. Perhaps they cause this strange behavior:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:id="@+id/product_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能有效,也可能无效,但使用
String.format(String, Object...)
似乎很适合您正在做的事情。首先将字符串
R.string.wishlist_price
更改为,然后使用以下命令调用它:
查看此内容以获取更多信息:使用字符串资源
This may or may not work, but using
String.format(String, Object...)
seems like a good fit for what you are doing.First change your string
R.string.wishlist_price
toand then call it using this:
Take a look at this for more information: Using String Resources
我解决了:
我将wrap_content更改为fill_parent:
I solved it:
I changed wrap_content to fill_parent: