Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
框架布局中的Android按钮布局_Android_Android Layout_Android Framelayout - Fatal编程技术网

框架布局中的Android按钮布局

框架布局中的Android按钮布局,android,android-layout,android-framelayout,Android,Android Layout,Android Framelayout,我有一个填充屏幕的框架布局和一个填充屏幕的表面视图。然后我有3个不同宽度的按钮。我想把这些按钮垂直地放在屏幕的右边缘上,均匀地间隔,这样顶部按钮就在屏幕的顶部,中间在中间,底部在底部。 伪布局: <FrameLayout layout_width="match_parent" layout_height="match_parent"> <SurfaceView layout_width="match_parent" layout_height="match_paren

我有一个填充屏幕的框架布局和一个填充屏幕的表面视图。然后我有3个不同宽度的按钮。我想把这些按钮垂直地放在屏幕的右边缘上,均匀地间隔,这样顶部按钮就在屏幕的顶部,中间在中间,底部在底部。 伪布局:

<FrameLayout layout_width="match_parent" layout_height="match_parent">

    <SurfaceView layout_width="match_parent" layout_height="match_parent"></SurfaceView>

    <ToggleButton android:layout_width="45dp"></ToggleButton>
    <ToggleButton android:layout_width="67dp"></ToggleButton>
    <ToggleButton android:layout_width="100dp"></ToggleButton>

</FrameLayout>
试试这个

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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <SurfaceView
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </SurfaceView>

        <RelativeLayout
            android:gravity="center_horizontal"
            android:layout_gravity="right"
            android:background="#f00"
            android:layout_width="100dp"
            android:layout_height="wrap_content" >

            <ToggleButton
                android:layout_width="45dp"
                  android:layout_centerHorizontal="true"
               android:layout_height="wrap_content" >
            </ToggleButton>

            <ToggleButton
                android:layout_width="67dp"
                android:layout_height="wrap_content"
               android:layout_centerHorizontal="true"
                android:layout_centerVertical="true" >
            </ToggleButton>

            <ToggleButton
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true" >
            </ToggleButton>
        </RelativeLayout>
    </FrameLayout>

</RelativeLayout>


附加快照是输出

您可以制作一个布局,然后在java代码中调用它时,只需根据屏幕的宽度和按钮的宽度排列按钮。将第一个按钮放在顶部,第二个按钮放在(屏幕高度/2-buttonheight/2),最后一个按钮放在(屏幕高度buttonheight)

注意:试着根据屏幕大小而不是dp或sp来排列按钮,因为屏幕大小可能会有所不同,这会把整个事情搞砸

祝你好运试试这个

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <SurfaceView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </SurfaceView>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical" >

        <ToggleButton
            android:id="@+id/toggleFirst"
            android:layout_width="45dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true" >
        </ToggleButton>

        <ToggleButton
            android:id="@+id/toggleSecond"
            android:layout_width="67dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/toggleFirst" >
        </ToggleButton>

        <ToggleButton
            android:id="@+id/toggleThird"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/toggleSecond" >
        </ToggleButton>
    </RelativeLayout>
</FrameLayout>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <SurfaceView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </SurfaceView>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical" >

        <ToggleButton
            android:id="@+id/toggleFirst"
            android:layout_width="45dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true" >
        </ToggleButton>

        <ToggleButton
            android:id="@+id/toggleSecond"
            android:layout_width="67dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/toggleFirst" >
        </ToggleButton>

        <ToggleButton
            android:id="@+id/toggleThird"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/toggleSecond" >
        </ToggleButton>
    </RelativeLayout>
</FrameLayout>