Scrollview не работает для Relative Layout - PullRequest
0 голосов
/ 06 мая 2018

Я пытаюсь заполнить Относительный макет с 4 видами карт в нем. Каждый просмотр карты состоит из одного изображения и просмотра текста. Я обернул все виды карточек в относительный макет и относительный макет в виде прокрутки. Это не работает. Если я удаляю scrollview, он работает нормально. Попытка размещения прокрутки внутри относительного макета. Но не сработало Код:

    <?xml version="1.0" encoding="utf-8"?>
    <Scrollview
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:fillViewport="true"
     android:layout_height="match_parent">

   <RelativeLayout
      android:id="@+id/activity_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#659D32"
      android:paddingBottom="16dp"
      android:paddingLeft="16dp"
      android:paddingRight="16dp"
      android:orientation="vertical"
      android:paddingTop="16dp"
      tools:context="com.example.MainActivity">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    app:cardCornerRadius="5dp"
    android:id="@+id/cardview_1"
    app:cardElevation="10dp"
    app:cardMaxElevation="15dp">

    <RelativeLayout
        android:layout_width="match_parent"

        android:layout_height="match_parent">


        <ImageView
            android:layout_width="match_parent"
            android:layout_height="170dp"
            android:src="@drawable/img_1"
            android:id="@+id/cardImage_bang"
            android:scaleType="centerCrop"/>

        <TextView
            android:layout_below="@+id/cardImage_1"
            android:id="@+id/cardTitle_1"
            android:gravity="center_horizontal"
            android:text="Text1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </RelativeLayout>
</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    app:cardCornerRadius="5dp"
    android:layout_below="@+id/cardview_1"
    android:id="@+id/cardview_2"
    app:cardElevation="10dp"
    android:layout_marginTop="10dp"

    app:cardMaxElevation="15dp">

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


        <ImageView
            android:layout_width="match_parent"
            android:layout_height="170dp"
            android:src="@drawable/img_2"
            android:id="@+id/cardImage_2"
            android:scaleType="centerCrop"/>

        <TextView
            android:layout_below="@+id/cardImage_2"
            android:id="@+id/cardTitle_2"
            android:gravity="center_horizontal"
            android:text="Text2"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>

Ответы [ 3 ]

0 голосов
/ 06 мая 2018

вы неправильно написали тег просмотра прокрутки. Это причина, по которой он не работает. Измените его с <Scrollview> на <ScrollView> и добавьте конечный тег вида прокрутки, например </ScrollView>, и снова запустите проект, он будет работать нормально.

Надеюсь, это поможет вам!

0 голосов
/ 06 мая 2018

1) Вы неправильно написали тег ScrollView, он должен быть <ScrollView>, а не <Scrollview>

2) Вы не закрыли тег <ScrollView> в конце кода

-> Вот правильный код

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:fillViewport="true"
 android:layout_height="match_parent">

<RelativeLayout
  android:id="@+id/activity_main"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#659D32"
  android:paddingBottom="16dp"
  android:paddingLeft="16dp"
  android:paddingRight="16dp"
  android:orientation="vertical"
  android:paddingTop="16dp"
  tools:context="com.example.MainActivity">

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
app:cardCornerRadius="5dp"
android:id="@+id/cardview_1"
app:cardElevation="10dp"
app:cardMaxElevation="15dp">

 <RelativeLayout
    android:layout_width="match_parent"

    android:layout_height="match_parent">


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="170dp"
        android:src="@drawable/img_1"
        android:id="@+id/cardImage_bang"
        android:scaleType="centerCrop"/>

    <TextView
        android:layout_below="@+id/cardImage_1"
        android:id="@+id/cardTitle_1"
        android:gravity="center_horizontal"
        android:text="Text1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>
</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
app:cardCornerRadius="5dp"
android:layout_below="@+id/cardview_1"
android:id="@+id/cardview_2"
app:cardElevation="10dp"
android:layout_marginTop="10dp"

app:cardMaxElevation="15dp">

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


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="170dp"
        android:src="@drawable/img_2"
        android:id="@+id/cardImage_2"
        android:scaleType="centerCrop"/>

    <TextView
        android:layout_below="@+id/cardImage_2"
        android:id="@+id/cardTitle_2"
        android:gravity="center_horizontal"
        android:text="Text2"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
0 голосов
/ 06 мая 2018

Надеюсь, это поможет вам .. (этот фрагмент работал в моем случае)

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
    android:fillViewport="true"
    android:paddingLeft="5dp"
    android:background="@color/bg"
    android:paddingRight="5dp">

    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:orientation="vertical"
            android:padding="10dp"
            android:weightSum="1">

        <!-- put entire thing here -->

    </RelativeLayout>
</ScrollView>
...