【问题标题】:ScrollView inside RelativeLayoutRelativeLayout 内的 ScrollView
【发布时间】:2017-12-10 17:03:11
【问题描述】:

我有一个协调器布局,上面有一个播放器信息栏,底部有一个导航栏,它们固定在那里。在中间我有一个包含滚动视图的相对布局,问题是滚动视图不滚动。此外,出于测试目的,我在滚动视图内部的相对布局周围放置了一个边框,正如您所看到的,布局的大小比它应该的要小。

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainCoordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.felix043.thedungeon.Main.MainActivity">

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

    <!-- Player Infos -->
    <include layout="@layout/layout_playerinfo"></include>

    <!-- ViewPager -->
    <RelativeLayout
        android:id="@+id/QuestRelLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <include
            layout="@layout/layout_viewpager">
        </include>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/playerinfo"
        android:layout_above="@+id/bottomNavLayout">
            <ScrollView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/playerinfo"
                android:layout_above="@+id/bottomNavLayout">

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_above="@+id/bottomNavLayout"
                    android:layout_below="@+id/playerinfo"
                    android:background="@drawable/text_border">

                    <Button
                        android:id="@+id/button8"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_above="@+id/button7"
                        android:layout_marginBottom="28dp"
                        android:layout_marginStart="72dp"
                        android:layout_toEndOf="@+id/button7"
                        android:text="Button" />

                    <Button
                        android:id="@+id/button7"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_alignParentStart="true"
                        android:layout_marginBottom="50dp"
                        android:layout_marginStart="41dp"
                        android:text="Button" />

                    <Button
                        android:id="@+id/button9"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_above="@+id/button8"
                        android:layout_marginBottom="29dp"
                        android:layout_marginEnd="12dp"
                        android:layout_toStartOf="@+id/button8"
                        android:text="Button" />

                    <Button
                        android:id="@+id/button10"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_above="@+id/button9"
                        android:layout_alignStart="@+id/button8"
                        android:layout_marginBottom="46dp"
                        android:layout_marginStart="24dp"
                        android:text="Button" />

                    <Button
                        android:id="@+id/button11"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_above="@+id/button10"
                        android:layout_toStartOf="@+id/button8"
                        android:text="Button" />

                    <Button
                        android:id="@+id/button12"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_alignParentEnd="true"
                        android:text="Button" />

                </RelativeLayout>
            </ScrollView>
    </RelativeLayout>
    <!-- BottomNav -->
    <include layout="@layout/layout_navbar"></include>

</RelativeLayout>

如蓝线所示,滚动视图上方还有更多按钮,但我无法滚动。

预期结果:滚动视图与屏幕一样大,没有播放器信息和导航栏,它应该是可滚动的。

【问题讨论】:

    标签: android android-scrollview android-coordinatorlayout android-relativelayout


    【解决方案1】:

    你可以通过两种方式来做

    1- 在滚动视图中添加 minHeight

      <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/playerinfo"
                    android:minHeight="200dp" //change as per your requirement
                    android:layout_above="@+id/bottomNavLayout">
    

    2- 使用 weight 的线性布局,它会自动调整屏幕大小。

    【讨论】:

    • minHeigth 的第一点确实使滚动视图变得更大,但不知何故,即使我有 match_parent,内部的相对布局也不会改变。线性布局和重量的第二点给了我相同的结果。不知何故,滚动视图内的相对布局不会调整。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 2014-04-18
    • 1970-01-01
    相关资源
    最近更新 更多