내 응용 프로그램에서 TableLayout을 사용하고 있습니다. 여기에는 4 개의 ImageView가 포함 된 4 개의 TableRow가 포함되어 있습니다. 내가 원하는 동작은 가장 짧은 치수에 맞게 레이아웃을 확장하는 것입니다.가로 모드에서 부모를 채우기 위해 Android TableLayout을 얻으려면 어떻게해야하나요?
세로 모드에서는 정상적으로 작동하지만 가로 모드에서는 비참하게 실패합니다.
documentation에서 TableRow layout_height는 항상 WRAP_CONTENT로 설정되어 있기 때문입니다. 개별 Views의 크기를 설정할 수는 있지만 View Layout_height를 FILL_PARENT로 설정하면 TableLayout이 전혀 렌더링되지 않습니다.
내가 누락 된 단순한 무언가가있는 것처럼 느껴집니다. 가로 모드에서 높이에 맞게 크기를 조정하기 위해 TableRowout을 사용하여 TableLayout을 가져 오는 방법이 있습니까?
XML 레이아웃 :
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*">
</TableLayout>
자바 :
public class Example extends Activity {
private TableLayout mTable;
private int[] mDrawableIds = { R.drawable.draw01, R.drawable.draw02, R.drawable.draw03, R.drawable.draw04, R.drawable.draw05, R.drawable.draw06, R.drawable.draw07, R.drawable.draw08, R.drawable.draw09, R.drawable.draw10, R.drawable.draw11, R.drawable.draw12, R.drawable.draw13, R.drawable.draw14, R.drawable.draw15, R.drawable.draw16 };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTable = (TableLayout)findViewById(R.id.table);
for (int j=0; j<4; j++) {
TableRow tr = new TableRow(this);
tr.setLayoutParams(new ViewGroup.LayoutParams( LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
for (int i=0; i<4; i++) {
ImageView iv = new ImageView(this);
iv.setImageResource(mDrawableIds[j*4+i]);
iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
iv.setAdjustViewBounds(true);
tr.addView(iv);
}
mTable.addView(tr);
}
}
}
사용 사례에 따라 GridView가 작동하지 않습니까? GridView 튜토리얼은 http://developer.android.com/guide/tutorials/views/hello-gridview.html –
GridView는 ImageViews를 가로 레이아웃으로 크기를 조정하지 않고 스크롤하려고합니다. 아마도 이미지 리소스를 작게 만들면 작동 할 수도 있습니다. 이미지의 크기를 조정하지 않기를 바랬습니다. –