我刚开始开发应用程序,试图制作一个电子商务应用程序,因为使用片段是一个更好的方式,而不是活动,我做了一个主页,我想首先显示操作栏,然后是最畅销的(前4个销售产品),然后是所有的产品。
这是一些我想实现image
我正在使用指南来约束视图分页器限制部分,但由于它是一个片段,它不是可滚动的,所以我必须将它设置为可滚动的,但第二次我设置为滚动视图,屏幕的大小增加,视图分页器得到扭曲。
无滚动视图My Home片段代码
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".home.HomeFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include
android:id="@+id/home_actionbar"
layout="@layout/actionbar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/top_selling_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15sp"
android:layout_marginTop="15sp"
android:text="@string/top_selling_heading"
android:textSize="14sp"
app:fontFamily="@font/roboto_bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/home_actionbar" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.45"
app:layout_constraintTop_toBottomOf="@id/top_selling_heading" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/top_seller_vp"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="5sp"
android:layout_margin="15sp"
android:clipToPadding="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/top_selling_heading"
app:layout_constraintBottom_toTopOf="@id/guideline2"
app:layout_constrainedHeight="true" />
<TextView
android:id="@+id/product_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/guideline2"
app:layout_constraintStart_toStartOf="@id/top_selling_heading"
app:layout_constraintEnd_toEndOf="@id/top_selling_heading"
android:text="@string/all_products_heading"
android:textSize="20sp"
android:fontFamily="@font/roboto_bold"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/productRV"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:scrollbars="vertical"
app:layout_constraintTop_toBottomOf="@id/product_heading"
android:layout_margin="10sp"
tools:listitem="@layout/product_item"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
有没有其他方法可以做到这一点?2请尽快帮助..
1条答案
按热度按时间xkrw2x1b1#
尝试在scrollView中使用LinearLayout(复制并粘贴)