请帮助我修复我的布局,我的类别被隐藏在最近的布局下面&它们几乎不显示。我尝试添加ScrollView,但在此代码中显示错误“binding = FragmentHomeBinding.inflate(layoutInflater,container,false)”。我已经附加了快照,以查看布局错误。对不起,我的愚蠢的错误,我是一个新手。
See the category text & Image is barely visible.
fragment_home.xml
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeFragment">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/bom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Best of the Month"
android:textSize="20sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcv_bomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</LinearLayout>
<LinearLayout
android:layout_below="@id/bom"
android:id="@+id/recent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Recent Wallpapers"
android:textSize="20sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcv_recentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</LinearLayout>
<LinearLayout
android:layout_below="@id/recent"
android:id="@+id/cat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Categories"
android:textSize="20sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcv_categories"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
</androidx.core.widget.NestedScrollView>
字符串
activity.main.xml
<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"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
</FrameLayout>
</androidx.core.widget.NestedScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_below="@id/nestedScrollview"
android:layout_alignParentBottom="true"
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:menu="@menu/bottom_nav_menu"
tools:ignore="MissingConstraints,NotSibling"
tools:layout_editor_absoluteX="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
</RelativeLayout>
</RelativeLayout>
型
首页片段.kt
class HomeFragment : Fragment() {
lateinit var binding: FragmentHomeBinding
lateinit var db: FirebaseFirestore
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentHomeBinding.inflate(layoutInflater, container, false)
db = FirebaseFirestore.getInstance()
db.collection("bestofthemonth").addSnapshotListener { value, error ->
val listBestOfTheMonth = arrayListOf<BomModel>()
val data = value?.toObjects(BomModel::class.java)
listBestOfTheMonth.addAll(data!!)
binding.rcvBomLayout.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL,true)
binding.rcvBomLayout.adapter = BomAdapter(requireContext(), listBestOfTheMonth)
}
型
2条答案
按热度按时间qv7cva1a1#
使用
ScrollView
,尝试从具有android:id="@+id/cat"
的LinearLayout
的android:layout_height="wrap_content"
更新android:layout_height="match_parent"
。lbsnaicq2#
您可以先使用scrollview并将framelayout作为子级,因为scrollview只能有1个直接子级
字符串
如果要在scrollview中包含recyclerview,请使用NestedScrollView代替ScrollView
型