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

后端 未结 3 1237
离开以前
离开以前 2020-11-27 02:27

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 anyon

相关标签:
3条回答
  • 2020-11-27 03:19

    Another way is to make android:layout_width="fill_parent" and android:layout_weight="1" this will also works fine!!!

    0 讨论(0)
  • 2020-11-27 03:19

    Use LinearLayout with your desired weightSum and create elements with equal layout_weight. Here is an example ...

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="5">
    
        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_share_white_36dp"/>
    
        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_search_white_36dp"/>
    
        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_event_note_white_36dp"/>
    
        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_brush_white_36dp"/>
    
        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_menu_white_36dp"/>
    </LinearLayout>
    

    So, the weight sum of all elements is 5. Here is the screenshot ...

    enter image description here

    Note that, Google Material Design icons are used. Hope this is helpful.

    0 讨论(0)
  • 2020-11-27 03:20

    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.

    0 讨论(0)
提交回复
热议问题