私は次のように TableLayout を持っています:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<Button
android:id="@+id/b1"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center" />
<Button
android:id="@+id/b2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" />
<Button
android:id="@+id/b3"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center" />
</TableRow>
</TableLayout>
各ボタンの幅は同じです。これらのボタンの高さを幅とまったく同じにしたい。私はプログラムでそれをやろうとしました:
Button b1 = (Button) findViewById(R.id.b1);
b1.setHeight(b1.getWidth());
しかし、それは機能しません (値が 0 になりました)。(onCreateメソッド内で)それを行うと、ボタンがまだ設定されていないためだと思います。