【问题标题】:horizontal layout scrolled水平布局滚动
【发布时间】:2015-09-13 06:19:19
【问题描述】:

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

这是我的代码:

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

【问题讨论】:

    标签: android horizontal-scrolling


    【解决方案1】:

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

    【讨论】:

    • 我照你说的做了,但没有任何改变
    • 您还应该为所有其他孩子使用layout_width="wrap_content",并为您的按钮设置特定宽度
    • 你说“按钮的特定宽度”是什么意思?如果当我给每个按钮一个固定大小时它不再响应
    • 类似“100dp”的东西。因为我知道您希望这些按钮更宽,就像您发布的图片一样。
    • 你应该明确你想要什么,因为在图片中,图像的大小都是一样的,这是固定的。
    猜你喜欢
    • 2013-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-04
    • 2019-12-11
    • 1970-01-01
    相关资源
    最近更新 更多