Wie kann ich Schaltflächen dynamisch an die Bildschirmgröße anpassen?
Ich habe Tasten in einem Table-Layout. Ich habe die Tasten dynamisch in der Tabelle Layout hier
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++;
}
}
}
Aber es scheint, als auf dem Bildschirm ich meine Tasten in der gleichen Breite und ein wenig größer Höhe will. Wie kann ich es tun? Meine Xmlfile ist jetzt so.
`<?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>`
Wenn 100 Hotels (mehr bedeutet), dann Tabellenlayout nicht korrekt angezeigt wird. Es ist besser, list/recyclerview/gridview layout zu verwenden. –