Android 表格行中的TextView不适合屏幕大小
将文本视图添加到行,从而将行添加到表布局。但是这一行被从屏幕上删除了Android 表格行中的TextView不适合屏幕大小,android,Android,将文本视图添加到行,从而将行添加到表布局。但是这一行被从屏幕上删除了 TextView point = new TextView(activity); TextView time = new TextView(activity); point.setTextSize(15); time.setTextSize(15); point.setPadding(5, 5, 5, 5); time.setPadding(5, 5, 5, 5); point.setText("s
TextView point = new TextView(activity);
TextView time = new TextView(activity);
point.setTextSize(15);
time.setTextSize(15);
point.setPadding(5, 5, 5, 5);
time.setPadding(5, 5, 5, 5);
point.setText("smthing something")
time.setText("smthing smthing")
row.addView(point);
row.addView(time);
tableLayout.addView(row);
如何在行中包装textview,以便在屏幕中包装该行。设置textview高度包装内容
TextView point = new TextView(activity);
TextView time = new TextView(activity);
LayoutParams layoutParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
point.setLayoutParams(layoutParams);
time.setLayoutParams(layoutParams);
point.setTextSize(15);
time.setTextSize(15);
point.setPadding(5, 5, 5, 5);
time.setPadding(5, 5, 5, 5);
point.setText("smthing something")
time.setText("smthing smthing")
row.addView(point);
row.addView(time);
tableLayout.addView(row);
point.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
谢谢穆克什,这解决了我大部分问题。:)穿过屏幕的文本被包裹在屏幕内。 因为我的第一列包含长文本,第二列包含短文本。。所以第一列必须适合多行,第二列必须适合单行。(将文本视图设置为单行或多行没有帮助) 因此,我将收缩列添加到“0”中,将拉伸列添加到“1”中。这解决了我的整个问题,现在也不需要设置布局参数 用于表格布局的XML:
<TableLayout
android:id="@+id/route_table"
android:layout_width="match_parent"
android:shrinkColumns="0"
android:padding="5dp"
android:stretchColumns="1">
<TableRow android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/row1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/stop"
android:background="@drawable/table_row"
android:padding="10dp"
android:text="Stop: "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/time"
android:layout_gravity="right"
android:background="@drawable/table_row"
android:padding="10dp"
android:text="Time: "/>
</TableLayout>
`谢谢穆克什,这解决了我大部分问题。:)