화면의 70 %를 차지하는 버튼이있는 5x5 테이블을 만들려고합니다. 이 아래에 스크롤 막대 (화면의 맨 아래 의미하는)와 함께 단추를 가로로 놓고 싶습니다. java 및 xml 파일은 다음과 같습니다. 출력 화면에서 5x5 테이블 만 생성 된 것을 볼 수 있으며 하단 공간은 공백으로 남습니다. 나는 안드로이드와 레이아웃에 익숙하지 않으므로 이것으로 나를 도와주세요. 감사!화면 하단에 가로 스크롤보기가있는 선형 레이아웃 만들기
XML 파일 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TableLayout
android:id="@+id/mainPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TableLayout>
<HorizontalScrollView
android:id="@+id/hsvMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/scroll_ll"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:scrollbars="horizontal"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
자바 파일 :
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.match_main_skl);
table = new TableLayout (this);
setControls();
hsv = new HorizontalScrollView(this);
ll = new LinearLayout(this);
mainTable();
}
private void setControls()
{
table = (TableLayout) findViewById(R.id.mainPage);
hsv = (HorizontalScrollView) findViewById(R.id.hsvMain);
ll = (LinearLayout) findViewById(R.id.scroll_ll);
}
private void mainTable()
{
//find screen size of the device (supports all versions)
Point windowSize = MAUIUtil.GetDefaultWindowSize(this);
int cellSize;
if (windowSize.x >= 0.70 * windowSize.y)
cellSize = windowSize.x/numColumns;
else cellSize = (int) ((0.70*windowSize.y)/numColumns);
**//5x5 TABLE**
TableRow.LayoutParams buttonRow = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT, 1.0f);
buttonRow.height = cellSize * numRows;
//buttonRow.height = windowSize.x;
table.setLayoutParams(buttonRow);
table.setStretchAllColumns(true);
for(int rw = 0; rw < numRows; rw++)
{
TableRow row = new TableRow(this);
row.setPadding(0, 0, 0, 0); //setPadding(left,top,right,bottom)
row.setId(ROW_ID_OFFSET + rw);//giving each row an id
TableLayout.LayoutParams tbLp = new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,1.0f);
tbLp.height = cellSize;
table.setLayoutParams(tbLp);
for(int col = 0; col < numColumns; col++)
{
int btnID = COLUMN_ID_OFFSET + (numColumns * (rw - 1)) + col;
//Adding buttons
Button btn = new Button(this);
btn.setId(btnID);
btn.setPadding(0, 0, 0, 0);
btn.setTypeface(Typeface.DEFAULT_BOLD);
btn.setBackgroundColor(Color.CYAN);
btn.setText(Integer.toString(btnID));
row.addView(btn);
}
table.addView(row);
}
**//LAST SCROLLABLE HORIZONTAL ROW**
hsv.addView(ll);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
llp.height = windowSize.y - cellSize;
hsv.setLayoutParams(llp);
LinearLayout sll = new LinearLayout(this);
for(int col = 0; col < scrNumColumns; col++)
{
int btnID = SCROLL_COLUMN_ID_OFFSET + col;
//Adding buttons
Button btn = new Button(this);
btn.setId(btnID);
btn.setPadding(0, 0, 0, 0);
btn.setTypeface(Typeface.DEFAULT_BOLD);
btn.setBackgroundColor(Color.RED);
btn.setText(Integer.toString(btnID));
sll.addView(btn);
sll.setGravity(Gravity.BOTTOM);
}
ll.addView(sll);
}
tableLayout에 Layout_weight를 .7로, linearLayout에 .3 – Manishika