谁能告诉我文本出了什么问题?长于一行的文本不会换行到下一行但超出屏幕.
以下是代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dip">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="4dip">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dip">
<TextView
android:id="@+id/reviewItemEntityName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="event/venue"
android:textColor="@color/maroon"
android:singleLine="true"
android:ellipsize="end"
android:textSize="14sp"
android:textStyle="bold"
android:layout_weight="1" />
<ImageView
android:id="@+id/reviewItemStarRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:src="@drawable/title_1_star" />
</LinearLayout>
<TextView
android:id="@+id/reviewItemDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Description comes here"
android:textSize="12sp"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
d-m*_*man 80
我自己修理了,关键是 android:width="0dip"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="4dip"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dip">
<TextView
android:id="@+id/reviewItemEntityName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/maroon"
android:singleLine="true"
android:ellipsize="end"
android:textSize="14sp"
android:textStyle="bold"
android:layout_weight="1" />
<ImageView
android:id="@+id/reviewItemStarRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" />
</LinearLayout>
<TextView
android:id="@+id/reviewItemDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:width="0dip" />
</LinearLayout>
<ImageView
android:id="@+id/widget01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_nxt"
android:layout_gravity="center_vertical"
android:paddingRight="5dip" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
hcp*_*cpl 40
只有正确回答这个问题,你需要家长设置为一个适当的宽度(在这种情况下FILL_PARENT,WRAP_CONTENT),并使用android:layout_weight=1了需要被包裹的TextView.
SingleLine 默认情况下处于启用状态,因此不会进行任何更改.
一width组为0px将工作,但不是一个很好的解决方案.
一些例子(在这次的tableview中),使用xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TableLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:stretchColumns="*"
android:id="@+id/tableLayout1">
<TableRow android:id="@+id/tableRow1" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="test1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="0" />
<TextView android:layout_weight="1"
android:text="test2 very long text that needs to be wrapped properly using layout_weight property and ignoring singleline since that is set by default..."
android:layout_width="fill_parent" android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
如果你想在代码中设置它,你正在寻找layout_weight作为第三个参数,就像在这个例子中设置为1一样:
row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
TextView label = new TextView(getApplicationContext());
label.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT, 1f));
Run Code Online (Sandbox Code Playgroud)
Kar*_*uez 19
您必须使用2个参数:
android:ellipsize="none" :文本未在文本视图宽度上剪切
android:scrollHorizontally="false" 文本根据需要包含尽可能多的行
Dha*_*eem 12
它足以在您的xml文件中使用.
android:singleLine="false".
Run Code Online (Sandbox Code Playgroud)
希望它会奏效.
祝一切顺利!
wir*_*d00 10
使用时,我无法使用任何这些解决方案TableLayout>TableRow>TextView.然后我找到了TableLayout.shrinkColumns="*".唯一有效的解决方案是强制TextView layout_width:250px等,但我不喜欢强制像这样的宽度.
如果使用表格,请尝试这样的事情.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*">
Run Code Online (Sandbox Code Playgroud)
请注意你需要 shrinkColumns="*"
这显然是在一个<LinearLayout>.所以像<LinearLayout> <TableLayout> <TableRow> <TextView>
引用:
http://code.google.com/p/android/issues/detail?id=4000
希望能帮助别人.
| 归档时间: |
|
| 查看次数: |
137108 次 |
| 最近记录: |