Представление прокрутки в представлении Recycler - PullRequest
0 голосов
/ 07 ноября 2018

Как я могу добавить представление прокрутки в XML-файл с относительным макетом, Recycler, TextView, Image View. Ниже приведен соответствующий код XML:

Пожалуйста, пройдите по приведенному ниже коду.

 <?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=".StoryList">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<ImageView
    android:id="@+id/skandaimagestory"
    android:src="@drawable/pictureskanda"
    android:layout_width="match_parent"
    android:layout_height="130dp" />
<TextView
    android:id="@+id/Heading"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/skandaimagestory"
    android:gravity="center"
    android:padding="17dp"
    android:text="SURVIVORS TALES"
    android:textSize="20dp"
    android:textStyle="bold" />

<LinearLayout
    android:layout_below="@+id/Heading"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:background="#f6facf"
        android:padding="10dp"
        android:id="@+id/story_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v7.widget.RecyclerView>

</LinearLayout>

</ScrollView>

Заранее спасибо.

Ответы [ 4 ]

0 голосов
/ 07 ноября 2018

Вы можете использовать NestedScrollView вместо обычного ScrollView, как это

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/skandaimagestory"
        android:src="@drawable/pictureskanda"
        android:layout_width="match_parent"
        android:layout_height="130dp" />
    <TextView
        android:id="@+id/Heading"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/skandaimagestory"
        android:gravity="center"
        android:padding="17dp"
        android:text="SURVIVORS TALES"
        android:textSize="20dp"
        android:textStyle="bold" />

    <LinearLayout
        android:layout_below="@+id/Heading"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.RecyclerView
            android:background="#f6facf"
            android:padding="10dp"
            android:id="@+id/story_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </android.support.v7.widget.RecyclerView>

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

А затем при инициализации RecyclerView просто добавьте эти две строки:

recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false);
0 голосов
/ 07 ноября 2018

Просто нужно иметь линейное расположение (вертикальное) в ScrollView

   <?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=".StoryList">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
     >
<ImageView
    android:id="@+id/skandaimagestory"
    android:src="@drawable/pictureskanda"
    android:layout_width="match_parent"
    android:layout_height="130dp" />
<TextView
    android:id="@+id/Heading"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/skandaimagestory"
    android:gravity="center"
    android:padding="17dp"
    android:text="SURVIVORS TALES"
    android:textSize="20dp"
    android:textStyle="bold" />

<LinearLayout
    android:layout_below="@+id/Heading"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:background="#f6facf"
        android:padding="10dp"
        android:id="@+id/story_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v7.widget.RecyclerView>

</LinearLayout>
</LinearLayout>
</ScrollView>
0 голосов
/ 07 ноября 2018

Внутри ScrollView макет должен иметь только один корневой макет. Обратите внимание, что я использовал LinearLayout в качестве корневого макета. Это может быть также 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=".StoryList">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <ImageView
        android:id="@+id/skandaimagestory"
        android:src="@drawable/pictureskanda"
        android:layout_width="match_parent"
        android:layout_height="130dp" />
        <TextView
        android:id="@+id/Heading"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/skandaimagestory"
        android:gravity="center"
        android:padding="17dp"
        android:text="SURVIVORS TALES"
        android:textSize="20dp"
        android:textStyle="bold" />

        <LinearLayout
        android:layout_below="@+id/Heading"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.RecyclerView
            android:background="#f6facf"
            android:padding="10dp"
            android:id="@+id/story_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </android.support.v7.widget.RecyclerView>

         </LinearLayout>
      </LinearLayout>

    </ScrollView>
0 голосов
/ 07 ноября 2018

Вы можете использовать android.support.v4.widget.NestedScrollView

...