예를 들어, 프로그래밍 방식으로 4 개의 tablerow를 만들고 각 tablerow 높이를 화면의 1/4 크기로 지정합니다. 각 tablerow 높이는 화면 크기의 절반입니다. 나는 다른 방법을 시도했지만, tablerow 높이는 변하지 않았다. 나는 tablerow 너비의 변화를 관리하지만 높이는 그렇지 않습니다. 여기 내 코드입니다 :Tablerow 높이가 변경되지 않았습니까?
@SuppressLint("NewApi")
public class GameActivity extends Activity {
private Context context;
public void drawTable(){
int i;
TableLayout table = new TableLayout(context);
table.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
//table.setStretchAllColumns(true);
//table.setShrinkAllColumns(true);
//table.setWeightSum(1.0F);
TableRow[] rows = new TableRow[5];
for(i = 0; i < 4; ++i){
rows[i] = new TableRow(context);
rows[i].setBackgroundResource(R.drawable.images214);
rows[i].setWeightSum((float)1.0);
rows[i].setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 10));
//rows[i].setScaleY(0.25F);
table.addView(rows[i]);
}
LinearLayout l = (LinearLayout) findViewById(R.id.linear);
l.addView(table);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
context = this;
// TableLayout table = new TableLayout(this);
// TableRow row1 = new TableRow(this);
// TableRow row2 = new TableRow(this);
// row1.addView(new EditText(this));
// row2.addView(new Button(this));
// table.addView(row1);
// table.addView(row2);
// //table.setBackground(getResources().getDrawable(R.drawable.ic_launcher));
// table.setBackgroundResource(R.drawable.ic_launcher);
// LinearLayout l = (LinearLayout) findViewById(R.id.linear);
// l.addView(table);
drawTable();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_game, menu);
return true;
}
}
XML : 각 테이블 행 설정 높이
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:layout_weight="1">
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical|horizontal">
</LinearLayout>
</ScrollView>
</RelativeLayout>
고맙습니다. 작동합니다. Scrollview가 필요하지 않습니다. 화면에서 모든 tablerows를 볼 수 없을 때 테스트 목적으로 추가했습니다. –