如何解决在Android上的横向模式下,无法使用视图分页器在片段内的嵌套滚动视图和回收者视图中滚动
我的活动需要滚动,回收者视图也需要滚动(目前已经滚动),请查看图片。
蓝色箭头区域不会滚动,这是整个活动。
任何帮助都会很棒!下面是完整布局的代码。
我的代码是:
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.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:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:fillViewport="true"
tools:context=".activities.FoodActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.cardview.widget.CardView
android:id="@+id/card_restaurant"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
android:layout_marginEnd="3dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:padding="15dp">
<ImageView
android:id="@+id/restaurant_Image"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_weight="2"
android:contentDescription="@null"
android:transitionName="smooth_transition">
</ImageView>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_weight="3"
android:orientation="vertical">
<TextView
android:id="@+id/restaurant_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="7dp"
android:drawablePadding="8dp"
android:fontFamily="@font/roboto_regular"
android:gravity="center_vertical"
android:maxLines="1"
android:text="Kentucky Fried Chicken"
android:textColor="@color/colorAccent"
android:textSize="21sp"
app:drawableStartCompat="@drawable/ic_baseline_restaurant_24" />
<TextView
android:id="@+id/restaurant_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:drawablePadding="8dp"
android:fontFamily="@font/roboto_light"
android:gravity="center_vertical"
android:text="Durbar Marg"
app:drawableStartCompat="@drawable/ic_baseline_location_on_24" />
<TextView
android:id="@+id/restaurant_hours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:drawablePadding="8dp"
android:fontFamily="@font/roboto_light"
android:gravity="center_vertical"
android:maxLines="1"
android:text="11:00 - 19:00"
app:drawableStartCompat="@drawable/ic_baseline_access_time_24" />
<TextView
android:id="@+id/min_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:drawablePadding="8dp"
android:fontFamily="@font/roboto_light"
android:gravity="center_vertical"
android:maxLines="1"
android:text="Rs. 500.00"
app:drawableStartCompat="@drawable/ic_baseline_forward_24" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:clipToPadding="false"
android:minHeight="?actionBarSize"
app:tabBackground="@drawable/tab_background"
app:tabGravity="fill"
app:tabIndicatorHeight="0dp"
app:tabMode="scrollable"
app:tabPadding="6dp"
app:tabRippleColor="@color/colorAccent"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@color/app_text_color" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<androidx.appcompat.widget.Toolbar
android:id="@+id/cart_view"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimaryDark"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/i_cart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:srcCompat="@drawable/ic_cart" />
<TextView
android:id="@+id/t_cart_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/i_cart"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:text="0"
android:textColor="@android:color/white" />
<View
android:id="@+id/divider"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/i_cart"
android:layout_alignBottom="@+id/i_cart"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_toEndOf="@+id/t_cart_count"
android:textColor="@android:color/white" />
<TextView
android:id="@+id/t_total_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/b_cart"
android:layout_toEndOf="@+id/divider"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:text="Rs. "
android:textColor="@android:color/white" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/b_cart"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="View Cart"
android:textColor="@android:color/white" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
<com.github.ybq.android.spinkit.SpinKitView
android:id="@+id/progress"
style="@style/SpinKitView.Large.ThreeBounce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"
app:SpinKit_Color="@color/loadingColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
片段被嵌入到视图分页器中,并在此处具有回收站视图:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。