简体   繁体   中英

how to create two fixed size views and one view spanned between them in android?

I want to create a screen

with two fixed size areas: one aligned to left, one to the right

and in between them another area which spans all the rest of the area?

If I make the middle view with property fill_parent it will catch all the area to the 3rd child.

what will be the effective property when layout_weight=0.X and layout_width=20dp .?

======

I have a linearLayout with orientation= horizontal .

It has a child with layout_weight=0.X and also layout_width=20dp .

What will be the effective property?

If you have a horizontal LinearLayout with the first child with a fixed width (eg layout_width="20dp" ), the second child with a non-zero weight (eg layout_weight="1" ) and the third with a fixed width (eg layout_width="20dp" ), then you should get the first aligned to the left, the third aligned to the right and the third filling the area between them.

It's also possible to do this with a RelativeLayout , but I'll leave that as the above solution should work just fine.

It will be something like this:

<LinearLayout android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="horizontal">

     <View android:id="@+id/view1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"/>

     <View android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_weight="1"/>

     <View android:id="@+id/view3"
           android:layout_width="20dp"
           android:layout_height="wrap_content"
           android:layout_weight="0"/>

</LinearLayout>

You should use android:layout_weight .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM