Android 水平滚动视图

10

大家好,我正在测试水平滚动视图时遇到了一个奇怪的问题。我在水平滚动视图中放置了一个按钮,并将布局高度和宽度设置为fill_parent,但该标记在布局中没有效果。让我们来看一下我的布局:

<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:fillViewport="true"
>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        >
        <Button             
            android:text="Button"
            android:id="@+id/button1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        </Button>
    </LinearLayout>

    </HorizontalScrollView>
如何在水平滚动视图中填充按钮到布局中?

在水平滚动视图中设置android:width="fill_parent"。 - N-JOY
@N-JOY,你试过吗?如果是的话,请将它作为答案。 - Sebastian Roth
@N-JOY 我加入了 <HorizontalScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true"
现在我可以看到按钮,但它无法填满整个布局。
- Bytecode
3个回答

6
问题可能出在android:width="wrap_content"上...因为您在水平滚动视图中使用了wrap content,而且它是线性布局和按钮的父级...这可能会导致所有问题...要么硬编码线性布局的大小,要么在水平滚动视图中放置android:width="fill_parent"

0
将这两个标签放在HorizontalScrollView中
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
在LinearLayout中设置方向
android:orientation="vertical"
在HorizontalScrollView中将android:layout_height="fill_parent"改为android:layout_height="wrap_content"

0
记住ScrollView的layout_height必须是wrap_content,fill_parent属性不影响ScrollView的高度,如果你想要一个按钮充满整个布局的屏幕,你应该将layout_height硬编码提到前面。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接