Je suis en train d'affecter la largeur par rapport aux colonnes dans un ListView qui est dans un TabHost, en utilisant layout_weight comme suggéré here:problème de mise en page Android - largeurs relatives en pour cent en utilisant le poids
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:id="@+id/triplist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="4px">
<TableRow>
<ListView android:id="@+id/triplistview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow>
<Button android:id="@+id/newtripbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Trip"/>
</TableRow>
[other tabs ...]
Ma définition de la ligne a 4 colonnes que je voudrais à la taille comme suit:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
android:padding="4px">
<TextView android:id="@+id/rowtripdate"
android:layout_weight=".2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:inputType="date"/>
<TextView android:id="@+id/rowodostart"
android:layout_weight=".2"
android:layout_width="0dip"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/rowodoend"
android:layout_weight=".2"
android:layout_width="0dip"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/rowcomment"
android:layout_weight=".4"
android:layout_width="0dip"
android:layout_height="wrap_content">
Malheureusement, il semble vouloir s'adapter à toutes les colonnes dans l'espace que le b utton occupe, par opposition à la largeur de l'écran. Ou peut-être y a-t-il une autre contrainte que je ne comprends pas. J'apprécierais votre aide.
alt text http://heeroz.com/layoutprob.png
Je passerais de px à dip dans vos mises en page pour prendre en charge différentes résolutions d'écran. –