简体   繁体   中英

4 rows of Buttons in LinearLayout fill screen width

I have a vertical LinearLayout with four horizontal LinearLayouts . Each horizontal layout contains 4 Buttons . I want the Buttons in each horizontal LinearLayout to fill the screen width evenly. Currently it looks like this:

在此处输入图片说明

The first Button of each row takes up all the width and the other 3 Buttons per row are not visible. Does anyone know how I can fix this?

<LinearLayout 
    android:id = "@+id/ll_screen_bttns"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:orientation="vertical"
    >
<LinearLayout 
    android:id="@+id/ll1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_weight = "1">
        <Button
            android:id="@+id/button0"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/size"
            android:background="@drawable/button"
            android:onClick="ButtonOnClick" 
            android:tag="0"/
        />  
        <Button
            android:id="@+id/button1"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/size"
            android:background="@drawable/button"
            android:onClick="ButtonOnClick" 
            android:tag="0"
            />

        <Button
            android:id="@+id/button2"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/size"
            android:background="@drawable/button"
            android:onClick="ButtonOnClick" 
            android:tag="0"
            />

        <Button
            android:id="@+id/button3"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/size"
            android:background="@drawable/button"
            android:onClick="ButtonOnClick" 
            android:tag="0"
            />
    </LinearLayout>

<LinearLayout 
    android:id="@+id/ll2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_weight = "1">
    <Button
        android:id="@+id/button4"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/size"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" 
        android:tag="0"
        />

    <Button
        android:id="@+id/button5"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/size"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" 
        android:tag="0"
       />

    <Button
        android:id="@+id/button6"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/size"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" 
        android:tag="0"
        />

    <Button
        android:id="@+id/button7"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/size"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" 
        android:tag="0"
        />

</LinearLayout>

<LinearLayout 
    android:id="@+id/ll3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_weight = "1">
    <Button
        android:id="@+id/button8"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/size"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" 
        android:tag="0"
      />

    <Button
        android:id="@+id/button9"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/size"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" 
        android:tag="0"
        />

    <Button
        android:id="@+id/button10"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/size"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" 
        android:tag="0"
        />

    <Button
        android:id="@+id/button11"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/size"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" 
        android:tag="0"
        />
</LinearLayout>

<LinearLayout 
android:id="@+id/ll4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight = "1">
    <Button
        android:id="@+id/button12"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/size"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" 
        android:tag="0"
        />

    <Button
        android:id="@+id/button13"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/size"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" 
        android:tag="0"
        />

    <Button
        android:id="@+id/button14"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/size"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" 
        android:tag="0"
        />

    <Button
        android:id="@+id/button15"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/size"
        android:background="@drawable/button"
        android:onClick="ButtonOnClick" 
        android:tag="0"
        />

    </LinearLayout>
</LinearLayout>

Abstract XML:

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

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

        <Button
            android:layout_width="0dp"
            android:layout_height="@dimen/size"
            android:layout_weight="1" />

        <Button
            android:layout_width="0dp"
            android:layout_height="@dimen/size"
            android:layout_weight="1" />

        <Button
            android:layout_width="0dp"
            android:layout_height="@dimen/size"
            android:layout_weight="1" />

        <Button
            android:layout_width="0dp"
            android:layout_height="@dimen/size"
            android:layout_weight="1" />

    </LinearLayout>  

    .
    .
    .

</LinearLayout>

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