Home > database >  Android: Linear layout inside scroll view is not showing more items inside it
Android: Linear layout inside scroll view is not showing more items inside it

Time:01-14

**Dear Seniors / Friends **

I am new in Android development and need your help related to my problem. I tried alot to resolve this issue by myself but I am unable to resolve.

I am creating an android app in which I have created an activity with scroll view. My main layout is Relative layout. under Relative layout I user One Linear Layout and in that layout I used Scroll view.`

`Under scroll view I created one child linear layout and 17 more linear layouts in the child linear layout.

My screen is going to disappear when add more Child linear layouts under scrollview-->linear layout.

I need to create 120 or more linear layouts in Child Linear layouts of Scroll view.

`

<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" android:background="@color/Newbackgroundclr" android:orientation="vertical" android:alpha=".9" tools:context=".AlquranActivity"> <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/Quranbackground"
    android:orientation="vertical"
    android:alpha=".9"
    android:gravity="center">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_marginBottom="15dp"
    android:orientation="horizontal"
    tools:ignore="UseCompoundDrawables">
    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center_vertical"
        android:contentDescription="@string/content_quran_image"
        app:srcCompat="@drawable/qurankareem" />
    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:fontFamily="cursive"
        android:gravity="center_vertical"
        android:text="Quran al Kareem"
        android:textAllCaps="false"
        android:textColor="@color/white"
        android:textSize="40sp"
        android:textStyle="bold" />
</LinearLayout>
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <!--All Sorahs Layouts starts here..... -->
        <!-- Surat al Fatiha upto Sorat al Naas -->

        <!--Fatiha -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="14dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/alfatiha" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Surat-ul-Fatiha"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #7 , Rukus #1"
                    android:textColor="@color/white"
                    android:textSize="13sp"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>
        <!--Baqara -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="6dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/albaqarah" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Surat-ul-Baqara"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #286 , Rukus #40"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>
        <!-- Aal -e- Imran -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="6dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/alimran" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Surah Aal e Imran"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #200 , Rukus #20"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>
        <!-- Nisa -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="4dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/annisa" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Surah An-Nisa"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #176 , Rukus #24"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>
        <!-- Maidah -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="6dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/almaidah" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Sorah Al-Ma’idah"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #120 , Rukus #16"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>
        <!-- An am -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="5dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/alanam" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Sorah Al-An’am"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #165 , Rukus #20"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>
        <!-- Al'araf -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="5dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/alaraf" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Sorah Al-A’raf"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #206 , Rukus #24"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>
        <!-- anfaal -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="8dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/anfaal" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Sorah Al-Anfal"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #75 , Rukus #10"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>

        </LinearLayout>
        <!-- Taubah -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="7dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/taubah" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Sorah At-Taubah"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #129 , Rukus #16"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>

        </LinearLayout>
        <!-- Younus -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="4dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/younus" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Surah Younas"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #109 , Rukus #11"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>

        </LinearLayout>
        <!-- Hud -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="6dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/hud" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Surah Hud"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #123 , Rukus #10"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>

        </LinearLayout>
        <!-- Yousuf -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="6dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/yousuf" />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Surah Yousaf"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #111 , Rukus #12"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>
        <!-- Ar'Rad-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/customeborder"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginRight="4dp"
                android:background="@drawable/customeborder"
                android:padding="6dp"
                android:tint="@color/white"
                app:srcCompat="@drawable/arraad" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/customeborder"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Surah Ar-Ra’d"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Verses #43 , Rukus #6"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>

        </LinearLayout>
        
    </LinearLayout>
</ScrollView> 

CodePudding user response:

You must be used RecyclerView for showing your data.

if you don't wanna use RecyclerView then use the code.

  • Use NestedScrollView instead of ScrollView.
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">


            </LinearLayout>
        </androidx.core.widget.NestedScrollView>
    </RelativeLayout>
  • Related