滚动的水平布局

时间:2015-09-13 06:19:20

标签: android horizontal-scrolling

我要设计一个这样的页面。我设计的页面的主要问题是它太短了。我希望我的每个按钮都更宽。就像你在图片中看到的那样。 如果我将修正号添加到我的线性布局,它可以工作,但它不再响应。 enter image description here

enter image description here

这是我的代码:

    <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>

1 个答案:

答案 0 :(得分:0)

在Horizo​​ntalLayout上,子宽度必须包含内容:

<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>
相关问题