在ScrollView

时间:2017-02-02 17:46:54

标签: android xml android-layout

我想在相对布局中显示4个回收站视图和textview。 recyclerviews是可见的,但textview不可见。我试图将relativelayout放在线性布局中,但没有成功。我想澄清一下,recyclerviews是横向的。在此先感谢请指导。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:scrollbars="none"
     android:fillViewport="true">


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/content_main"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:paddingBottom="@dimen/activity_vertical_margin"
     android:paddingLeft="@dimen/activity_horizontal_margin"
     android:paddingRight="@dimen/activity_horizontal_margin"
     android:paddingTop="@dimen/activity_vertical_margin"
     app:layout_behavior="@string/appbar_scrolling_view_behavior"
     tools:context="com.himesh.icm.MainActivity"
     tools:showIn="@layout/app_bar_main"
     android:orientation="vertical">

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Some Random Text"
    android:clickable="true"
    android:textColor="@color/colorAccent"/>


<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:layout_marginTop="200dp"
    android:scrollbars="vertical" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:layout_marginTop="50dp"
    android:scrollbars="vertical"
    android:layout_below="@+id/recycler_view1"/>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:layout_marginTop="50dp"
    android:scrollbars="vertical"
    android:layout_below="@+id/recycler_view2"/>

   <android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:layout_marginTop="50dp"
    android:scrollbars="vertical"
    android:layout_below="@+id/recycler_view3"/>


</RelativeLayout>
</ScrollView>

1 个答案:

答案 0 :(得分:-1)

tools:showIn="@layout/app_bar_main"

移除app:layout_behavior="@string/appbar_scrolling_view_behavior"RelativeLayout

尝试这种布局:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.himesh.icm.MainActivity">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">

        <RelativeLayout
            android:id="@+id/content_main"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin">

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:text="Some Random Text"
                android:textColor="@color/colorAccent" />


            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/textView1"
                android:layout_marginTop="200dp"
                android:clipToPadding="false"
                android:scrollbars="vertical" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/recycler_view1"
                android:layout_marginTop="50dp"
                android:clipToPadding="false"
                android:scrollbars="vertical" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/recycler_view2"
                android:layout_marginTop="50dp"
                android:clipToPadding="false"
                android:scrollbars="vertical" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/recycler_view3"
                android:layout_marginTop="50dp"
                android:clipToPadding="false"
                android:scrollbars="vertical" />


        </RelativeLayout>
    </ScrollView>
</RelativeLayout>