1

I think my question must be really stupid, but I just spent one hour seeking on network without result ...

I have a linear Layout with 3 TextView, and I want them to share to whole width of the screen

Here is a picture to illustrate !

http://img845.imageshack.us/i/putaindlayout.png/

I'd like to have each textview just behind images ...

Thanks ...

1 Answer 1

2

Use weight attribute. Set weight 1 to all your TextFields and they will take all the space. Something like this should work.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView
        android:layout_width="wrap_content" 
        android:id="@+id/textView1"
        android:layout_height="wrap_content" 
        android:text="TextView"
        android:gravity="center_horizontal" 
        android:layout_weight="1" />
    <TextView 
        android:layout_width="wrap_content" 
        android:id="@+id/textView2"
        android:layout_height="wrap_content" 
        android:text="TextView"
        android:gravity="center_horizontal" 
        android:layout_weight="1" />
    <TextView 
        android:layout_width="wrap_content" 
        android:id="@+id/textView3"
        android:layout_height="wrap_content" 
        android:text="TextView"
        android:gravity="center_horizontal" 
        android:layout_weight="1" />
</LinearLayout>
1
  • Thanks for the tips, but with this code, the screen is divided in 3 parts, and in each part the text in TextView are not in center, but on the left ... May 5, 2011 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.