[android]how to get 4 buttons at the bottom and each 2 button is beside each other

让人想犯罪 __ 提交于 2019-12-25 03:36:19

问题


I find majority teaching online is about 2 button beside each other but I couldnt obtain the arrangement wanted as in the image. When I put in the relativelayout, all the button overlap together no matter I put android:layout_above:"XX" All my total, 0.00, back and pay button , i need to out them at the bottom. this is my original code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/billTV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

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

    <Button
        android:id="@+id/backB"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Back" />

    <Button
        android:id="@+id/payB"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Pay" />
</LinearLayout>


回答1:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/billTV"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.55"
        android:text="TextView" />

    <TextView
        android:id="@+id/total"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

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

        <Button
            android:id="@+id/backB"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Back" />

        <Button
            android:id="@+id/payB"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Pay" />
    </LinearLayout>

</LinearLayout>

Try some thing like this.




回答2:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        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="vertical" >

            <TextView
                android:id="@+id/billTV"
                android:layout_width="fill_parent"
                android:layout_height="394dp"
                android:text="TextView" />
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        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="vertical" >

            <TextView
                android:id="@+id/total"
                android:layout_width="fill_parent"
                android:layout_height="32dp"
                android:text="TextView" />

        </LinearLayout>

    </LinearLayout>

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

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

            <Button
                android:id="@+id/backB"
                android:layout_width="106dp"
                android:layout_height="wrap_content"
                android:text="Back" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="right"
            android:orientation="vertical" >

            <Button
                android:id="@+id/payB"
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:text="Pay" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

try this



来源:https://stackoverflow.com/questions/9807778/androidhow-to-get-4-buttons-at-the-bottom-and-each-2-button-is-beside-each-oth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!