J'ai créé une vue de tableau en utilisant la disposition de table et la rangée de table, et puis je suis confronté au problème de taille, je veux que la taille soit égale à la taille table. Je le crée avec TableRow dynamiquement, voici mon code:Android - Comment faire pour que la taille de la ligne de table soit égale à
TableLayout xml.
<android.widget.HorizontalScrollView
android:id="@+id/hv_cust_prop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarAlwaysDrawHorizontalTrack="false">
<TableLayout
android:id="@+id/table_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:measureWithLargestChild="true"
android:stretchColumns="*"
android:weightSum="1" />
</android.widget.HorizontalScrollView>
Élément TableRow xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal|fill_vertical"
android:gravity="fill_horizontal|center_vertical"
android:orientation="vertical">
<FrameLayout
android:id="@+id/container_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal|fill_vertical"
android:background="@drawable/cell_header_bg">
<TextView
android:id="@+id/txt_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal|fill_vertical"
android:layout_margin="2dp"
android:gravity="center"
android:maxWidth="150dp"
android:padding="7dp"
android:text="Header 1"
android:textStyle="bold" />
</FrameLayout>
</LinearLayout>
Ligne génératrice Java.
row = new TableRow(getActivity());
TableRow.LayoutParams lp = new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1);
lp.gravity = Gravity.FILL;
row.setLayoutParams(lp);
View head = LayoutInflater.from(getActivity()).inflate(R.layout.item_cell_cust_prop, null);
FrameLayout container = (FrameLayout) head.findViewById(R.id.container_header);
container.setBackgroundResource(R.drawable.cell_bg);
TextView txtHeader = (TextView) head.findViewById(R.id.txt_header);
try {
txtHeader.setText(object.getString("CV_VALUE"));
} catch (JSONException e) {
txtHeader.setText("erorr");
e.printStackTrace();
}
row.addView(head);
tableContent.addView(row);
avec tableContent est TableLayout du précédent xml.
Je veux une hauteur de la colonne suit la plus grande hauteur identique à la colonne avec le texte enroulé.
Toute aide sera appréciée. Merci,
hi @Omi merci, mais je veux que mon textview ait la largeur maximale, donc, il sera enveloppé si le texte dépasse la largeur maximale. :( mais, merci pour la réponse. :) –
bonjour @yascodwiy essayer le code de mise à jour – Omi