매트릭스 구조로 레이아웃을 만드는 방법을 알고 싶습니다. 예 : 첫 번째 행에는 5 개의 버튼이 있고 두 번째 원시에는 5 개의 버튼이 있습니다.Eclipse android layout 매트릭스 구조
나는 진짜 운이없이 그것을하려고 노력했다. 내 프로그래밍 플랫폼은 Eclipse, Java, android입니다.
매트릭스 구조로 레이아웃을 만드는 방법을 알고 싶습니다. 예 : 첫 번째 행에는 5 개의 버튼이 있고 두 번째 원시에는 5 개의 버튼이 있습니다.Eclipse android layout 매트릭스 구조
나는 진짜 운이없이 그것을하려고 노력했다. 내 프로그래밍 플랫폼은 Eclipse, Java, android입니다.
시도 TableLayout입니다. :이 레이아웃은 자식을 행과 열로 정렬합니다.
다음은 첫 번째 행에 3 개의 버튼을 만들고 두 번째 행에 3 개의 버튼을 만드는 매우 기본적인 TableLayout입니다.
TableLayout에 2 개의 TableRow Object를 추가하여 각 행에 5 개의 버튼을 갖도록 확장 할 수 있습니다.
<?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="match_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<Button
android:id="@+id/TextView04" android:text="Row 1 Button 1"
android:layout_weight="1" android:background="#dcdcdc"
android:textColor="#000000"
android:padding="20dip" android:gravity="center"/>
<Button
android:id="@+id/TextView04" android:text="Row 1 Button 2"
android:layout_weight="1" android:background="#d3d3d3"
android:textColor="#000000"
android:padding="20dip" android:gravity="center"/>
<Button
android:id="@+id/TextView04" android:text="Row 1 Button 3"
android:layout_weight="1" android:background="#cac9c9"
android:textColor="#000000"
android:padding="20dip" android:gravity="center"/>
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<Button
android:id="@+id/TextView04" android:text="Row 2 Button 1"
android:layout_weight="1" android:background="#dcdcdc"
android:textColor="#000000"
android:padding="20dip" android:gravity="center"/>
<Button
android:id="@+id/TextView04" android:text="Row 2 Button 2"
android:layout_weight="1" android:background="#d3d3d3"
android:textColor="#000000"
android:padding="20dip" android:gravity="center"/>
<Button
android:id="@+id/TextView04" android:text="Row 2 Button 3"
android:layout_weight="1" android:background="#cac9c9"
android:textColor="#000000"
android:padding="20dip" android:gravity="center"/>
</TableRow>
</TableLayout>
TableLayout 컨테이너에는 행, 열 또는 셀의 경계선이 표시되지 않습니다.
당신이 동적으로 자바 코드를 사용하여 몇 행을 추가하려는 경우 경우, 아래의 예는 다음과 같습니다
TableLayout tl = (TableLayout) findViewById(R.id.yourtablelayout);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
/* Create a Button to be the row-content. */
Button b = new Button(this);
b.setText("add your button text here ");
b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
/* Add Button to row. */
tr.addView(b);
/* Add row to TableLayout. */
//tr.setBackgroundResource(R.drawable.sf_gradient_03);
tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
감사합니다. 정말로 도와 주셔서 감사합니다. – zeev1079
확실! 레이아웃을 사용자 정의해야 위 레이아웃의 요구 사항에 따라 미용 효과를 추가 할 수 있습니다! – AADProgramming
TableRows와 TableLayout을은 XML 코딩에 의해 –
내가 수동으로 할 수있는 갈 수있는 좋은 방법이 될 것입니다 . 같은 relativelayout 등 – zeev1079
GridView보십시오. 쉽고 원하는대로 정확하게 할 수 있습니다. –