Je veux créer un TableLayout
qui remplit son parent où chaque rangée a la même taille. Que dois-je faire pour obtenir des rangées de hauteur égale?Comment créer un TableLayout qui remplit le parent et qui a des lignes de hauteur égale?
0
A
Répondre
0
Vous pouvez utiliser l'attribut layout_weight pour les éléments TableRow de votre mise en page. Cela distribuera la hauteur de manière égale (si vous définissez vos poids pour être le même) sur la hauteur parentale. Tout d'abord, définissez le parent android:weightSum="1"
, puis assurez-vous que tous les poids des lignes individuelles correspondent à 1
.
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:weightSum="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- Row 1 -->
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.5"
android:padding="5dp" >
<!-- Your columns here... -->
</TableRow>
<!-- Row 2 -->
<TableRow
android:id="@+id/tableRow2"
android:layout_weight="0.5"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:padding="5dp" >
<!-- Your columns here... -->
</TableRow>
</TableLayout>
J'espère que cela aide. S'il vous plaît essayer et laissez-moi savoir si c'est ce que vous cherchez.
0
try this:
In your layout
<TableLayout
android:id="@+id/sub_cat_layout"
android:layout_width="match_parent"
android:layout_below="@+id/subcat_headerlayout"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="0dp"
>
</TableLayout>
InActivity
TableLayout SubCAtLyt = (TableLayout)findViewById(R.id.sub_cat_layout);
View v1 = null;
LinearLayout linear_pmain = new LinearLayout(getActivity());
linear_pmain.setOrientation(LinearLayout.HORIZONTAL);
LayoutInflater vii = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TableRow tblRow = new TableRow(getActivity());
tblRow.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
arrBookDetails = db.Book(subCatid);
int catAllLength = arrCatAllBookDetails.size();
for (int j = 0; j < catAllLength; j++) {
List<String> lBookDetails = arrBookDetails.get(j);
//Row value layout
String book = lBookDetails.get(10);
v1 = vii.inflate(R.layout.sub_bottomthubnail, null);
TextView txt = (TextView) v1.findViewById(R.id.txtg1);
txt.setText(book);
txt.setTypeface(tface, Typeface.NORMAL);
tblRow.addView(v1, j);
}
SubCAtLyt.addView(tblRow);