Please help me fix my layout my Categories are hidden below the recent layout & they’re barely showing. I’ve tried to add the ScrollView but it’s showing the error " binding = FragmentHomeBinding.inflate(layoutInflater, container, false)" in this code. I’ve attached the snapshot to see the layout error. Sorry for my silly mistakes I am a newbie.
See the category text & Image is barely visible.
frame_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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">
<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>
Home Fragment.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
Answers
With using
ScrollView
try to updateandroid:layout_height="match_parent"
fromandroid:layout_height="wrap_content"
ofLinearLayout
that haveandroid:id="@+id/cat"
.You can use scrollview first with framelayout as child because scrollview can only have 1 direct child
Use NestedScrollView instead ScrollView if you want to include recyclerview inside scrollview