どのように画面サイズに応じて動的にボタンのサイズを変更できますか?
私はテーブルレイアウトでボタンを持っています。私はここで
TableLayout tblHotels=(TableLayout) findViewById(R.id.tblLayout);
if(hotels != null){
int index=0;
for (int i=0; i<(hotels.length/2); i++) {
TableRow tblRow=new TableRow(getApplicationContext());
tblHotels.addView(tblRow);
tblRow.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.MATCH_PARENT));
for (int j=0;j<2; j++)
{
tblRow.addView(hotels[index]);
hotels[index].setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT, 1.0F));
hotels[index].setOnClickListener(this);
index++;
}
}
}
テーブルレイアウトで動的にボタンを置くしかし、私が同じ幅とちょっと大きめの高さで私のボタンをしたい画面のように表示されます。どうすればいいですか?私のxmlfileはこれのようなものです。
`<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.arzucaki.sherwoodhotels.Hotels"
android:weightSum="1"
>
<TableLayout
android:id="@+id/tblLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.6"
android:gravity="bottom"
android:orientation="vertical"
android:layout_alignParentTop="true">
</TableLayout>
</RelativeLayout>`
、その後、テーブルレイアウトが正しく表示されません。 list/recyclerview/gridviewレイアウトを使用する方が良いでしょう。 –