【问题标题】:ScrollView cramps ListViewScrollView 抽筋 ListView
【发布时间】:2015-02-11 06:49:10
【问题描述】:

我不想为我的布局需要(需要?)创建一个 FragmentStatePagerAdapter 成为顶层的 ScrollView。 现在,当我创建布局时,LinearLayout(或 RelativeLayout 无关紧要)从不使用完整的滚动视图容器,即使我将 layout_height 和 layoutg_width 设置为“match_parent”(fill_parent 或 wrap_content 也不起作用) 这是布局的一部分

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/intro_scroll_view_1"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:orientation="vertical"
        android:background="@drawable/intro_dummy">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".80"
            android:layout_gravity="center_horizontal">

            <ImageView
                android:layout_width="223dp"
                android:layout_height="60dp"
                android:id="@+id/imageView"
                android:layout_centerVertical="true"
                android:layout_centerHorizontal="true"
                android:src="@drawable/logo"/>

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".20"
            android:layout_gravity="center_horizontal">

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@+id/button">

            </RelativeLayout>

            <Button
                android:background="@null"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Get Started"
                android:id="@+id/button"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:textColor="#ffffff"
                android:padding="2dp"/>

        </RelativeLayout>

    </LinearLayout>
</ScrollView>

既然我使用了 match_parent 它应该使用整个屏幕吗?不,它只使用屏幕的随机位

如果我删除 Scrollview 并将 LinearLayout 设置为顶层元素,它会使用所有内容。所以我猜我在 Scrollview 描述中遗漏了一些东西来让它使用一切?

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    使用

    android:fillViewport="true"
    

    在您的 ScrollView 中,http://developer.android.com/reference/android/widget/ScrollView.html#attr_android:fillViewport

    定义滚动视图是否应该拉伸其内容以填充视口。

    【讨论】:

    • 你也应该把你的滚动视图和线性布局android:layout_width="fill_parent"android:layout_height="fill_parent"
    • 哦,谢谢 :D 想知道为什么这不在开发人员的示例中。在 ScreenSlideAcitivy 示例中它丢失了:/
    猜你喜欢
    • 2011-11-15
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    • 2015-07-29
    • 2013-05-07
    • 2012-04-06
    • 2016-08-11
    • 1970-01-01
    相关资源
    最近更新 更多