2010-10-13 6 views
1

Je suis très très nouveau sur Android.TextView remplit le 80% des écrans

Je veux mettre un TextView dans un LinearLayout qui remplit les 80% de la hauteur de LinearLayout.

Comment puis-je faire cela? ou Comment peut-on assigner un pourcentage sur la largeur et la hauteur?

Merci.

Répondre

3

Une disposition comme celle-ci fonctionnera. La clé est l'attribut layout_weight. La documentation d'Android n'est pas très bonne pour cet attribut. Notez que le second TextView (il pourrait être n'importe quoi) est requis sinon, le premier TextView occupera tout l'espace.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
    <TextView android:layout_weight="0.8" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" 
    android:background="#FFC300" 
    /> 
    <TextView android:layout_weight="0.2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="second text box" 
    /> 
</LinearLayout>