Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

layout - Android: How to make all elements inside LinearLayout same size?

I would like to create a dialog to display a video title and tags. Below text I would like to add buttons View, Edit and Delete and make these elements same size. Does anyone know how to modify .xml layout file in order to make elements inside LinearView same size?

The current layout file looks like this:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:orientation="vertical">

    <LinearLayout 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:orientation="vertical">

          <TextView 
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content" 
              android:id="@+id/txtTitle" android:text="[Title]" >
          </TextView>

          <TextView 
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" 
              android:id="@+id/txtTags"            
              android:text="[Tags]" >
          </TextView>

    </LinearLayout>

    <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal">

        <Button 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:id="@+id/btnPlay" 
           android:text="View">
        </Button>

        <Button 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/btnEdit" 
            android:text="Edit">
        </Button>

        <Button 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/btnDelete" 
            android:text="Delete">
        </Button>

    </LinearLayout>

</LinearLayout>

I would appreciate if anyone could show the solution by modifying the pasted file content.

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use android:layout_width="0px" and android:layout_weight="1" on the three Buttons. That says the buttons should take up no more than 0 pixels, but the three of them should split any extra space between them. That should give you the visual effect you wish.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...