ScrollViewにあるTablelayoutでプログラムでボタンのサイズを設定したい。
ここに私のXMLファイルがあります
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarFadeDuration="1000"
android:scrollbarSize="12dip" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tablay"
tools:context=".MainActivity"
>
<Button
android:id="@+id/start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/open" />
<TableRow>
<ImageButton
android:layout_width="16sp"
android:layout_height="16sp"
android:contentDescription="@string/Delete"
android:src="@drawable/ic_delete" />
</TableRow>
</TableLayout>
</ScrollView>
ここに私のJavaファイルがあります
private void setList(){
/* Create a new row to be added. */
TableRow tr;
ImageButton delbtn;
int btnsize;
tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
delbtn = new ImageButton(this);
//delbtn.setText("Delete");
//delbtn.setTextSize(TypedValue.COMPLEX_UNIT_SP,sys_def_char_font);
btnsize = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sys_def_char_font, getResources().getDisplayMetrics());
delbtn.setId(i);
delbtn.setImageResource(R.drawable.ic_delete);
delbtn.setLayoutParams(new LayoutParams(btnsize,btnsize));
tr.addView(delbtn);
tablay.addView(tr);
}
ボタンをxmlファイルに相互に追加すると、すべて問題ありません。
しかし、プログラムで追加しようとしています。そして、プログラムで追加したボタンを小さくしたいので、setLayoutParams を使用してパラメータを設定します。
ただし、プログラムで追加したボタンは setLayoutParams() の後にありません。
どこが間違っているのか誰か教えてください。