[英]Setting size of Buttons in TableRow
我有一个(可能)平庸但烦人的问题。 我有TableRow
。 在“行”中,有9个按钮,但其中只有5个可见。 如果我缩短代码,它将看起来像这样:
XML:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="fill_vertical">
<TableRow
android:id="@+id/row"/>
</TableLayout>
JAVA:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pokusy);
TableRow row = (TableRow)findViewById(R.id.row);
for(int i = 0; i < 9; i++){
Button b = new Button(this);
row.addView(b);
}
}}
我已经尝试了在互联网上找到的所有内容(例如setWidth
, setLayoutParams
, android:layout_width="..."
),但在屏幕上仍然只能看到9个按钮中的5个。 有人可以帮我吗?
稍微修改您的XML以使其工作。 rinkleColumns属性使列适合所需的TableLayout
参数。 “ *”将其应用于所有列。
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill_vertical"
android:shrinkColumns="*" > <!-- this makes the difference -->
<TableRow
android:id="@+id/row"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.