skip to Main Content

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


  1. With using ScrollView try to update android:layout_height="match_parent" from android:layout_height="wrap_content" of LinearLayout that have android:id="@+id/cat".

    Login or Signup to reply.
  2. You can use scrollview first with framelayout as child because scrollview can only have 1 direct child

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
        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"
        android:orientation="vertical"
        tools:context=".HomeFragment">
    
        <FrameLayout 
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            //other layout/views
    
        </FrameLayout>
    </ScrollView>
    

    Use NestedScrollView instead ScrollView if you want to include recyclerview inside scrollview

    <?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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".HomeFragment">
    
        <FrameLayout 
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            //other layout/views
    
        </FrameLayout>
    </androidx.core.widget.NestedScrollView
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search