【问题标题】:Align RecyclerView below a ScrollView在 ScrollView 下方对齐 RecyclerView
【发布时间】:2015-08-11 22:13:43
【问题描述】:

我正在尝试设计一个在顶部有标题和一些文本的布局,然后在其下方有一个 RecyclerView 的 cmets。文本可能会很长,因此我将其放入ScrollView。我的代码导致TextViewsRecyclerView 相互重叠:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                android:paddingBottom="@dimen/activity_vertical_margin">

                <TextView
                    android:id="@+id/title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:textSize="18sp"
                    android:textStyle="bold"
                    android:paddingBottom="5dp"
                    />

                <TextView
                    android:id="@+id/text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="14sp"
                    android:layout_below="@id/title"
                    android:paddingTop="5dp"
                    />
            </RelativeLayout>
    </ScrollView>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/commentlist"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        />

</RelativeLayout>

【问题讨论】:

    标签: android android-layout scrollview android-recyclerview


    【解决方案1】:

    因为你使用的是 RelaiveLayout 将其替换为 LinearLayout 并将方向属性设置为“垂直”

    【讨论】:

    • 这也导致只显示TextViewsRecyclerView 似乎被隐藏了。
    【解决方案2】:

    这样做:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <ScrollView
            android:id="@+id/scroll"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="@dimen/activity_horizontal_margin"
                    android:paddingRight="@dimen/activity_horizontal_margin"
                    android:paddingTop="@dimen/activity_vertical_margin"
                    android:paddingBottom="@dimen/activity_vertical_margin">
    
                    <TextView
                        android:id="@+id/title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentTop="true"
                        android:textSize="18sp"
                        android:textStyle="bold"
                        android:paddingBottom="5dp"
                        />
    
                    <TextView
                        android:id="@+id/text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="14sp"
                        android:layout_below="@id/title"
                        android:paddingTop="5dp"
                        />
                </RelativeLayout>
        </ScrollView>
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/commentlist"
            android:scrollbars="vertical"
            android:layout_below="@+id/scroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            />
    
    </RelativeLayout>
    

    【讨论】:

    • 这导致只显示TextViewsRecyclerView 似乎被隐藏了。
    • 你需要在相对布局中做android:layout_height="wrap_content",编辑我的代码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-30
    • 2017-12-08
    • 1970-01-01
    • 2014-10-20
    相关资源
    最近更新 更多