Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.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_Horizontal Scrolling - Fatal编程技术网

Android 水平布局已滚动

Android 水平布局已滚动,android,horizontal-scrolling,Android,Horizontal Scrolling,我要设计一个这样的页面。我设计的页面的主要问题是它太短了。我希望我的每个按钮都更宽。就像你在照片上看到的一样。 如果我在线性布局中添加FixNumber,它会工作,但不再响应。 这是我的代码: <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk

我要设计一个这样的页面。我设计的页面的主要问题是它太短了。我希望我的每个按钮都更宽。就像你在照片上看到的一样。 如果我在线性布局中添加FixNumber,它会工作,但不再响应。

这是我的代码:

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

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

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

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

                 <Button
                    android:id="@+id/button2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                     android:background="#FF2200"
                    android:layout_weight="1.0"
                    android:text="Button" />
                <Button
                    android:id="@+id/button1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@android:color/white"
                    android:layout_weight="1.0"
                    android:text="Button" />
                 <Button
                    android:id="@+id/button2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                     android:background="#FF2200"
                    android:layout_weight="1.0"
                    android:text="Button" />
                <Button
                    android:id="@+id/button1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@android:color/white"
                    android:layout_weight="1.0"
                    android:text="Button" />
                 <Button
                    android:id="@+id/button2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                     android:background="#FF2200"
                    android:layout_weight="1.0"
                    android:text="Button" />




            </LinearLayout>

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

                <Button
                    android:id="@+id/button1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@android:color/white"
                    android:layout_weight="0.1"
                    android:text="Button" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                     android:background="#FF2200"
                    android:layout_weight="0.1"
                    android:text="Button" />
                <Button
                    android:id="@+id/button1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@android:color/white"
                    android:layout_weight="0.1"
                    android:text="Button" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                     android:background="#FF2200"
                    android:layout_weight="0.1"
                    android:text="Button" />
                <Button
                    android:id="@+id/button1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@android:color/white"
                    android:layout_weight="0.1"
                    android:text="Button" />



            </LinearLayout>
        </LinearLayout>





    </HorizontalScrollView>


</LinearLayout>

在水平布局上,子对象的宽度必须包裹内容:

<HorizontalScrollView android:layout_width="match_parent" android:layout_height="match_parent" >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        ...
    </LinearLayout>
</HorizontalLayout>

我照你说的做了,但它没有改变任何东西。你还应该为所有其他孩子使用layout_width=wrap_内容,并为你的按钮设置一个特定的宽度。你说为你的按钮设置一个特定的宽度是什么意思?如果我给每个按钮一个固定的大小,它就不再像100dp那样响应了。因为我知道你希望那些按钮更宽,就像你发布的图片一样。你应该澄清你想要什么,因为在图片中,图片的大小都是一样的,这是固定的。