Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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_Xml_Layout - Fatal编程技术网

需要Android布局创建帮助吗

需要Android布局创建帮助吗,android,xml,layout,Android,Xml,Layout,我正在尝试制作一个“游戏板”,两边各有WASD和箭头,如下所示: 但是我不希望箭头垫在WASD的下方,而是希望它们与WASD在左侧,箭头在右侧处于同一条“线” 有人能帮我解决这个问题吗(我不会发布我的代码,因为它是垃圾,甚至不接近解决方案,只是为了说明我正在尝试做什么) 试试这个: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="

我正在尝试制作一个“游戏板”,两边各有WASD和箭头,如下所示:

但是我不希望箭头垫在WASD的下方,而是希望它们与WASD在左侧,箭头在右侧处于同一条“线”

有人能帮我解决这个问题吗(我不会发布我的代码,因为它是垃圾,甚至不接近解决方案,只是为了说明我正在尝试做什么)


试试这个:

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

    <LinearLayout
        android:id="@+id/mainArrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/keypad"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center|top"
                android:orientation="horizontal" >

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:focusable="false"
                    android:text="W" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center|top"
                android:orientation="horizontal"
                android:weightSum="9" >

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:focusable="false"
                    android:text="A" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:focusable="false"
                    android:text="S" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:focusable="false"
                    android:text="D" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/arrow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center|top"
                android:orientation="horizontal" >

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:focusable="false"
                    android:text="↑" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center|top"
                android:orientation="horizontal"
                android:weightSum="9" >

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:focusable="false"
                    android:text="←" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:focusable="false"
                    android:text="↓" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:focusable="false"
                    android:text="→" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>


有很多方法,我们最好的方法就是修复您现有的布局。不需要编码,只需要xml布局文件。@weston好吧,我制作xml并不是为了创建解决方案,只是为了举例说明,但如果你认为它会有帮助,我已经将它添加到帖子中了。相对布局会做你喜欢的事。其他人也会这样。@ChiefTwoPencils不是我没有尝试相对布局或其他任何东西,只是我没有按照我需要的方式来做。你也可以使用GridLayout(2行6列)这很好,但是有没有办法在WASD/箭头下方放置另一个水平布局?因为仅仅放置另一个布局会导致它位于箭头组的右侧
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="2" >

    <LinearLayout
        android:id="@+id/mainArrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/keypad"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center|top"
                android:orientation="horizontal" >

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:focusable="false"
                    android:text="W" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center|top"
                android:orientation="horizontal"
                android:weightSum="9" >

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:focusable="false"
                    android:text="A" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:focusable="false"
                    android:text="S" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:focusable="false"
                    android:text="D" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/arrow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center|top"
                android:orientation="horizontal" >

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:focusable="false"
                    android:text="↑" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center|top"
                android:orientation="horizontal"
                android:weightSum="9" >

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:focusable="false"
                    android:text="←" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:focusable="false"
                    android:text="↓" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:focusable="false"
                    android:text="→" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>