简体   繁体   English

为什么我的布局没有显示在滚动视图中?

[英]Why does my layout not showing inside scrollview?

ViewPager not showing inside ScrollView. ViewPager 未显示在 ScrollView 中。 Without scrollview my viewpager is working perfectly fine!!没有滚动视图,我的 viewpager 工作得很好!

I tried to wrap viewpager inside another layout, I tried scrollview to wrap inside another relative layout and some other ways, but none of working.我试图将 viewpager 包装在另一个布局中,我尝试将 scrollview 包装在另一个相对布局和其他一些方式中,但没有任何效果。

What should I do now?我现在该怎么办? Please see below XML file请参阅下面的 XML 文件

What I tried:我试过的:

android:fillViewport="true"
        android:fitsSystemWindows="true"

Code:代码:

<?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=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:theme="@style/AppTheme.AppBarOverlay">

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


            <ImageView
                android:id="@+id/map"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_marginLeft="6dp"
                android:layout_marginTop="10dp"
                android:src="@drawable/map"
                android:tint="@color/colorRed" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="10dp"
                android:layout_toRightOf="@+id/map"
                android:fontFamily="sans-serif"
                android:textColor="@color/colorBlack"
                android:text="Phase - 1, Peenya, Bengaluru"
                android:textSize="16sp" />

            <ImageView
                android:id="@+id/pay"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_marginTop="10dp"
                android:layout_toLeftOf="@+id/profile_pic"
                android:layout_marginRight="8dp"
                android:src="@drawable/ic_baseline_payment_24"
                android:tint="@color/colorBlack" />

            <ImageView
                android:id="@+id/profile_pic"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="10dp"
                android:layout_marginRight="5dp"
                android:src="@drawable/circle_profile1" />

        </RelativeLayout>

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorWhite">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginRight="6dp"
                android:orientation="vertical">


                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/rounded_edittext_states"
                    android:hint="Search for restaurants, cuisines..."
                    android:textColorHint="@color/colorDarkGray"
                    android:textColor="@color/colorBlack"
                    android:padding="10dp" />

            </LinearLayout>

        </androidx.appcompat.widget.Toolbar>

        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabIndicatorColor="@color/colorRed"
            app:tabMode="fixed"
            app:tabTextColor="@color/colorBlack" />
    </com.google.android.material.appbar.AppBarLayout>

    <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/app_bar">


    <androidx.viewpager.widget.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    </ScrollView>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:itemBackground="@color/colorPrimary"
        app:itemIconTint="@color/colorBlack"
        app:itemTextColor="@color/colorWhite"
        app:menu="@menu/bottom_navigation_main" />


</RelativeLayout>

the viewpager is displayed when I make the height match_parent when I try the code.当我尝试代码时使高度 match_parent 时会显示 viewpager。

<ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/app_bar">

Try using the parent layout as coordinator layout not the relative layout and in your scroll view use this attribute尝试使用父布局作为协调器布局而不是相对布局,并在滚动视图中使用此属性

app:layout_behaviour="@string/appbar_scropling_view_behaviour"

It's better to use a nested scroll view instead of a scroll view as it have nested scroll view is advanced version of scroll view.最好使用嵌套滚动视图而不是滚动视图,因为嵌套滚动视图是滚动视图的高级版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM