почему myscrollview не прокручивается в студии android - PullRequest
0 голосов
/ 04 августа 2020

У меня есть макет с таким кодом, я хочу создать макет, такой как профиль, в приложении isntagram. но я не знаю, почему мой scrollview вообще не работает

это мой код

<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"
android:id="@+id/containerProfile"
tools:context=".ui.profile.ProfileActivity">

    <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView"
    android:fillViewport="true"
    android:paddingTop="10dp"
    android:layout_below="@+id/view">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/rl1">
        <RelativeLayout
            android:id="@+id/myprofile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin">

        </RelativeLayout>

        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tab_Layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/myprofile"/>

        <androidx.viewpager.widget.ViewPager
            android:id="@+id/view_Pager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_below="@+id/tab_Layout">
        </androidx.viewpager.widget.ViewPager>
    </RelativeLayout>
</ScrollView>

может кто-нибудь объяснить почему? это мой полный xml код https://pastebin.com/XwgsA2cT

Ответы [ 3 ]

0 голосов
/ 04 августа 2020

ScrollView не работает с несколькими дочерними макетами. Оберните весь свой макет в относительный / линейный макет, а затем оберните этот макет с помощью ScrollView.

0 голосов
/ 04 августа 2020

Попробуйте вместо этого NestedScrollView, это сработает. Сделайте NestedScrollView родительскую группу просмотра. Также убедитесь, что его закрывающий тег находится на одном уровне. В вашем случае у вас есть несоответствие между открывающими и закрывающими тегами .. Вы начали с RelativeLayout, а закрыли с </ScrollView>. Ваша родительская группа просмотра <RelativeLayout>, сделайте это <NestedScrollView> и закройте родительскую группу просмотра с помощью </NestedScrollView>

Обновить

<NestedScrollView 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:id="@+id/containerProfile"
tools:context=".ui.profile.ProfileActivity">

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView"
    android:fillViewport="true"
    android:paddingTop="10dp"
    android:layout_below="@+id/view">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/rl1">
        <RelativeLayout
            android:id="@+id/myprofile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin">

        </RelativeLayout>

        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tab_Layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/myprofile"/>

        <androidx.viewpager.widget.ViewPager
            android:id="@+id/view_Pager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_below="@+id/tab_Layout">
        </androidx.viewpager.widget.ViewPager>
    </RelativeLayout>
</NestedScrollView> 

Примечание - Не забудьте обновить свое представление ids

0 голосов
/ 04 августа 2020

Попробуйте вместо этого использовать вложенный режим прокрутки

...