lag when scrolling activity - java

In my applications main activity I have 19 images with textview under them in a NestedScrollView. Images size is about 25 KB and when I run application on LG G3 it has lag. What can I do? And caching images can help me?
XML file:
<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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="ir.aftabeshafa.shafadoc.MainActivity"
tools:showIn="#layout/app_bar_main">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView"
android:src="#mipmap/brain" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/brain"
android:id="#+id/textView"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView2"
android:src="#mipmap/dentist" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/dentist"
android:id="#+id/textView2"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView3"
android:src="#mipmap/dermatologist" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/dermatologist"
android:id="#+id/textView3"
android:layout_marginTop="8dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView4"
android:src="#mipmap/digestive" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/digestive"
android:id="#+id/textView4"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView5"
android:src="#mipmap/ent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/ent"
android:id="#+id/textView5"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView6"
android:layout_marginTop="8dp"
android:src="#mipmap/eye" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/eye"
android:id="#+id/textView6"
android:layout_marginTop="8dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView7"
android:src="#mipmap/general" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/general"
android:id="#+id/textView7"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView8"
android:src="#mipmap/gynecologist" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/gynecologist"
android:id="#+id/textView8"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView9"
android:src="#mipmap/heart" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/heart"
android:id="#+id/textView9"
android:layout_marginTop="8dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView10"
android:src="#mipmap/infection" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/infection"
android:id="#+id/textView10"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView11"
android:src="#mipmap/inner" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/inner"
android:id="#+id/textView11"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView12"
android:src="#mipmap/kidney" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/kidney"
android:id="#+id/textView12"
android:layout_marginTop="8dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>

Your layout is too complex. You have a RelativeLayout as root element (bad idea), which only has 1 child (a NestedScrollView) - your RelativeLayout is redundant and only causing unnecessary churn.
Start by removing the RelativeLayout and make your ScrollView the top layout. See if you can streamline the rest of the layout by using a TextView with drawableLeft instead of having a TextView and Imageview.
Instead of loading everything from the get go, you could consider using a RecyclerView and load only a subset of the images, and let your adapter load more as the user scrolls.

Related

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

**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>
You must be used RecyclerView for showing your data.
Yes you can try ListView or GridView for showing data but RecyclerView is batter option for showing large data.
because RecycleView is save your memory.
Explorer widget https://developer.android.com/develop/ui/views/layout/recyclerview
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>

Android Java fragment is displayed on half screen

I have developing android app.
I have problem when displaying list of card in recycler-view that within in fragment_auction_products.xml.
When I navigate to FragmentAuctionProducts, I have the
this is the problem
As you can see my list starts showing after 50% space is empty... How I can solve this?
My fragment_auction_products.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:gravity="top"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/home_auction_products_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:gravity="top"
android:layout_marginTop="10dp"/>
<ProgressBar
android:id="#+id/home_auction_products_loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminateDrawable="#drawable/spinner_ring"
android:indeterminateOnly="true" />
</LinearLayout>
My recycler view item:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="10dp"
android:gravity="center"
android:background="#drawable/layer_shadow"
android:orientation="horizontal">
<ImageView
android:id="#+id/home_auction_products_recycler_view_image"
android:layout_margin="4dp"
android:layout_width="125dp"
android:layout_height="150dp"
android:src="#drawable/card_example_1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginStart="15dp"
android:layout_marginEnd="10dp"
android:orientation="vertical"
android:paddingTop="15dp">
<TextView
android:id="#+id/home_auction_products_recycler_view_title"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/muli_bold"
android:text="Title"
android:textColor="#color/colorBlack"
android:textSize="14dp" />
<TextView
android:id="#+id/home_auction_products_recycler_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/muli_bold"
android:text="id"
android:textColor="#color/colorBlack"
android:textSize="0dp" />
<TextView
android:id="#+id/home_auction_products_recycler_view_current_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/muli_bold"
android:text="50000 тг"
android:textColor="#color/colorTextYellow"
android:textSize="16dp" />
<TextView
android:id="#+id/home_auction_products_recycler_view_start_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/muli"
android:text="start-price"
android:textColor="#color/colorBlack"
android:textSize="12dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp"
android:background="#drawable/auction_products_shape"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingTop="2dp"
android:paddingRight="4dp"
android:paddingBottom="2dp">
<TextView
android:id="#+id/home_auction_products_recycler_view_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/muli"
android:gravity="center"
android:text="10"
android:textColor="#color/colorWhite"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/muli"
android:gravity="center"
android:text="ДНЕЙ"
android:textColor="#color/colorWhite"
android:textSize="6dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/auction_products_shape"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingTop="2dp"
android:paddingRight="4dp"
android:paddingBottom="2dp">
<TextView
android:id="#+id/home_auction_products_recycler_view_hour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/muli"
android:gravity="center"
android:text="12"
android:textColor="#color/colorWhite"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/muli"
android:gravity="center"
android:text="ЧАСОВ"
android:textColor="#color/colorWhite"
android:textSize="6dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:orientation="horizontal">
<TextView
android:id="#+id/home_auction_products_recycler_view_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_mdi_keyboard_arrow_right"
android:fontFamily="#font/muli"
android:textColor="#color/colorTextGray"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
My main container where I call my fragments:
<?xml version="1.0" encoding="utf-8"?>
<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/colorWhite"
tools:context=".activity.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/bottom_nav_bar">
<FrameLayout
android:id="#+id/main_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:windowBackground"
app:menu="#menu/menu" />
</RelativeLayout>
Change the FrameLayout height to match_parent.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottom_nav_bar">
<FrameLayout
android:id="#+id/main_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ScrollView>
Just use android:layout_alignParentTop.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/home_auction_products_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:gravity="top"
android:layout_marginTop="10dp"/>
<ProgressBar
android:id="#+id/home_auction_products_loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminateDrawable="#drawable/spinner_ring"
android:indeterminateOnly="true" />
</LinearLayout>
Hope this helps.

How to add a scroll view in an Android app

I want to add scroll in my XML without editing the following code. Is there any way of adding it in the following XML? I tried by adding Scroll view and then linear view but it makes the view cut. Is there any way of making it better, I have searched other repository but I didn't find a solution.
<LinearLayout 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=".Activity.BookSeatsActivity"
android:orientation="vertical"
android:weightSum="12"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:gravity="center_horizontal"
android:layout_marginTop="20dp"
android:weightSum="5"
android:orientation="horizontal"
>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/wheel"
android:src="#drawable/mywheel"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:layout_marginEnd="17dp"
/>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/grid"
android:layout_marginTop="10dp"
android:layout_below="#+id/wheel"
android:padding="1dp"
android:numColumns="5"
/>
</RelativeLayout>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".4"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".6"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"
android:weightSum="3"
android:layout_marginEnd="10dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/seat_open"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:text="Available"
android:paddingStart="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/seat_booked"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:paddingStart="5dp"
android:text="Unavailable"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/seat_selected"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:paddingStart="5dp"
android:gravity="center_vertical"
android:text="Selected"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginEnd="10dp"
android:orientation="horizontal"
android:layout_marginStart="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Seat Selected : "
android:textSize="18dp"
android:padding="5dp"
android:paddingStart="10dp"
android:textColor="#android:color/black"
android:textStyle="bold"
android:fontFamily="#font/montserrat_regular"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tv_seat_selected"
android:textStyle="bold"
android:textColor="#android:color/black"
android:textSize="18dp"
android:padding="5dp"
android:paddingStart="10dp"
android:gravity="center_vertical"
android:layout_marginTop="10dp"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bt_booking_details"
android:textStyle="bold"
android:textColor="#android:color/white"
android:textSize="17dp"
android:layout_margin="10dp"
android:text="Enter Booking Details"
android:fontFamily="#font/montserrat_regular"
android:background="#drawable/circular_button"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Please use the below code snippet for the XML file and change the image view as per your needs.
<LinearLayout 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"
android:weightSum="12"
tools:context=".MainActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="8"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="5">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="3">
<ImageView
android:id="#+id/wheel"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:layout_marginEnd="17dp"
android:layout_marginRight="17dp"
android:src="#drawable/sports" />
<GridView
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/wheel"
android:layout_marginTop="10dp"
android:numColumns="5"
android:padding="1dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".4" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_weight=".6"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/toys" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:paddingStart="5dp"
android:paddingLeft="5dp"
android:text="Available" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/mobile" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:paddingStart="5dp"
android:paddingLeft="5dp"
android:text="Unavailable" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/home" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:paddingStart="5dp"
android:paddingLeft="5dp"
android:text="Selected" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:padding="5dp"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:text="Seat Selected : "
android:textColor="#android:color/black"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_seat_selected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:padding="5dp"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:textColor="#android:color/black"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1">
<Button
android:id="#+id/bt_booking_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Enter Booking Details"
android:textColor="#android:color/white"
android:textSize="17dp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Please try the following code, I just changed the scroll view to be match_parent for width and height and the linear layout to be match_parent for width& wrap_content for height.
Please note that this view won't scroll till you run it on a small screen device.
and please change the images as you need.
<LinearLayout 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"
android:weightSum="12">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:gravity="center_horizontal"
android:layout_marginTop="20dp"
android:weightSum="5"
android:orientation="horizontal"
>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/wheel"
android:src="#drawable/ic_launcher_background"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:layout_marginEnd="17dp"
/>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/grid"
android:layout_marginTop="10dp"
android:layout_below="#+id/wheel"
android:padding="1dp"
android:numColumns="5"
/>
</RelativeLayout>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".4"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".6"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"
android:weightSum="3"
android:layout_marginEnd="10dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/ic_launcher_background"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:text="Available"
android:paddingStart="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/ic_launcher_background"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:paddingStart="5dp"
android:text="Unavailable"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/ic_launcher_background"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:paddingStart="5dp"
android:gravity="center_vertical"
android:text="Selected"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginEnd="10dp"
android:orientation="horizontal"
android:layout_marginStart="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Seat Selected : "
android:textSize="18dp"
android:padding="5dp"
android:paddingStart="10dp"
android:textColor="#android:color/black"
android:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tv_seat_selected"
android:textStyle="bold"
android:textColor="#android:color/black"
android:textSize="18dp"
android:padding="5dp"
android:paddingStart="10dp"
android:gravity="center_vertical"
android:layout_marginTop="10dp"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bt_booking_details"
android:textStyle="bold"
android:textColor="#android:color/white"
android:textSize="17dp"
android:layout_margin="10dp"
android:text="Enter Booking Details"
android:background="#drawable/ic_launcher_background"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>

Android CoordinatorLayout Scrolling Entire View

I have a ViewPager activity that uses CoordinatorLayout and a couple of tabs. In each tab, I have these pretty large Fragments that will not fit all the way onto a user's screen. I want the user to be able to scroll up and down to see the entire Fragment. I obviously also want the scroll events to be picked up by CoordinatorLayout which will hide the Toolbar. I have the Toolbar hiding on scroll working, but after the Toolbar is hidden from the CoordinatorLayout scroll, I cannot scroll anymore to see the rest of my view below.
How can I get this behavior?
Here is my simple ViewPager activity layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="com.cryptobuddy.ryanbridges.cryptobuddy.currencylist.CurrencyListTabsActivity"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/appBarLayout"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_currency_details"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways|snap"/>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/currencyTabsViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
Here is my Fragment layout that I cannot for the life of me get to scroll:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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"
tools:context="com.cryptobuddy.ryanbridges.cryptobuddy.chartandprice.CurrencyDetailsTabsActivity"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:fillViewport="true">
<android.support.v4.widget.SwipeRefreshLayout 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:id="#+id/swipe_refresh_layout"
android:layout_gravity="center|bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.constraint.ConstraintLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/graph_fragment_horizontal_margin"
android:paddingRight="#dimen/graph_fragment_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.cryptobuddy.ryanbridges.cryptobuddy.chartandprice.CurrencyDetailsTabsActivity">
<TextView
android:id="#+id/current_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/graphFragmentDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/current_price" />
<TextView
android:id="#+id/percent_change"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/graphFragmentDateTextView" />
<com.github.mikephil.charting.charts.LineChart
android:id="#+id/chart"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:focusableInTouchMode="true"
android:padding="0dp"
app:layout_constraintBottom_toTopOf="#+id/guideline5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline6" />
<com.nex3z.togglebuttongroup.SingleSelectToggleGroup
android:id="#+id/chart_interval_button_grp"
android:layout_width="384dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="#+id/guideline6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/percent_change"
app:tbgCheckedButton="#+id/dayButton"
app:tbgChildSpacing="auto">
<com.nex3z.togglebuttongroup.button.CircularToggle
android:id="#+id/dayButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/oneDay"
android:textSize="16sp"
app:tbgMarkerColor="#color/colorAccent" />
<com.nex3z.togglebuttongroup.button.CircularToggle
android:id="#+id/weekButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Week"
android:textSize="16sp"
app:tbgMarkerColor="#color/colorAccent" />
<com.nex3z.togglebuttongroup.button.CircularToggle
android:id="#+id/monthButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Month"
android:textSize="16sp"
app:tbgMarkerColor="#color/colorAccent" />
<com.nex3z.togglebuttongroup.button.CircularToggle
android:id="#+id/threeMonthButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/threeMonth"
android:textSize="16sp"
app:tbgMarkerColor="#color/colorAccent" />
<com.nex3z.togglebuttongroup.button.CircularToggle
android:id="#+id/yearButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Year"
android:textSize="16sp"
app:tbgMarkerColor="#color/colorAccent" />
<com.nex3z.togglebuttongroup.button.CircularToggle
android:id="#+id/allTimeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/All"
android:textSize="16sp"
app:tbgMarkerColor="#color/colorAccent" />
</com.nex3z.togglebuttongroup.SingleSelectToggleGroup>
<android.support.constraint.Guideline
android:id="#+id/guideline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
<android.support.constraint.Guideline
android:id="#+id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.15" />
<TableLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/guideline5">
<TableRow
android:id="#+id/nameTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tableNameTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Name" />
<TextView
android:id="#+id/tableNameDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="TextView"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/symbolTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tableSymbolTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Symbol" />
<TextView
android:id="#+id/tableSymbolDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="TextView"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/priceUSDTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tablePriceUSDTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Price (USD)" />
<TextView
android:id="#+id/tablePriceUSDDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="TextView"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/priceBTCTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tablePriceBTCTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Price (BTC)" />
<TextView
android:id="#+id/tablePriceBTCDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="TextView"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/volUSDTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tableVolUSDTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="24h Volume" />
<TextView
android:id="#+id/tableVolUSDDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="TextView"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/mktCapUSDTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tableMktCapTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Market Cap" />
<TextView
android:id="#+id/tableMktCapDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="TextView"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/availableSupplyTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tableAvailableSupplyTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Available Supply" />
<TextView
android:id="#+id/tableAvailableSupplyDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="TextView"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/totalSupplyTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tableTotalSupplyTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Total Supply" />
<TextView
android:id="#+id/tableTotalSupplyDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="TextView"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/maxSupplyTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tableMaxSupplyTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Max Supply" />
<TextView
android:id="#+id/tableMaxSupplyDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="TextView"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/changeTitlesTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/table1hrChangeTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Change 1hr"
android:textAlignment="center" />
<TextView
android:id="#+id/table24hrChangeTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Change 24hr"
android:textAlignment="center" />
<TextView
android:id="#+id/tableWeekChangeTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Change 7d"
android:textAlignment="center" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/table1hrChangeDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView"
android:textAlignment="center" />
<TextView
android:id="#+id/table24hrChangeDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="TextView"
android:textAlignment="center" />
<TextView
android:id="#+id/table7dChangeDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="TextView"
android:textAlignment="center" />
</TableRow>
</TableLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
From your fragment code:
Remove the outermost NestedScrollView. You don't need it.
Add app:layout_behavior="#string/appbar_scrolling_view_behavior" to the SwipeRefreshLayout which has become the new parent.
Change the inner ScrollView to NestedScrollView.
Let us know if it works.
I found the solution. There were 2 problems:
I was using guidelines in the ConstraintLayout.
I had the height/width of some elements in my ConstraintLayout set to match_constraint.
I removed the guidelines and gave all of my layout elements raw height/width values in dp. That seems to have fixed the problem.
It seems that the scrolling does not play nicely fitting elements inside of guidelines
Here is my xml now:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/graphFragmentNestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/graph_fragment_horizontal_margin"
android:paddingRight="#dimen/graph_fragment_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<TextView
android:id="#+id/current_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/graphFragmentDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/current_price" />
<TextView
android:id="#+id/percent_change"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/graphFragmentDateTextView" />
<com.nex3z.togglebuttongroup.SingleSelectToggleGroup
android:id="#+id/chart_interval_button_grp"
android:layout_width="362dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/percent_change"
app:tbgCheckedButton="#+id/dayButton"
app:tbgChildSpacing="auto">
<com.nex3z.togglebuttongroup.button.CircularToggle
android:id="#+id/dayButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/oneDay"
android:textSize="16sp"
app:tbgMarkerColor="#color/colorAccent" />
<com.nex3z.togglebuttongroup.button.CircularToggle
android:id="#+id/weekButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Week"
android:textSize="16sp"
app:tbgMarkerColor="#color/colorAccent" />
<com.nex3z.togglebuttongroup.button.CircularToggle
android:id="#+id/monthButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Month"
android:textSize="16sp"
app:tbgMarkerColor="#color/colorAccent" />
<com.nex3z.togglebuttongroup.button.CircularToggle
android:id="#+id/threeMonthButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/threeMonth"
android:textSize="16sp"
app:tbgMarkerColor="#color/colorAccent" />
<com.nex3z.togglebuttongroup.button.CircularToggle
android:id="#+id/yearButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Year"
android:textSize="16sp"
app:tbgMarkerColor="#color/colorAccent" />
<com.nex3z.togglebuttongroup.button.CircularToggle
android:id="#+id/allTimeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/All"
android:textSize="16sp"
app:tbgMarkerColor="#color/colorAccent" />
</com.nex3z.togglebuttongroup.SingleSelectToggleGroup>
<com.github.mikephil.charting.charts.LineChart
android:id="#+id/chart"
android:layout_width="match_parent"
android:layout_height="275dp"
android:layout_marginTop="8dp"
android:focusableInTouchMode="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/chart_interval_button_grp" />
<TableLayout
android:id="#+id/tableLayoutGraphFragment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingBottom="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/chart">
<TableRow
android:id="#+id/nameTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/lightGray">
<TextView
android:id="#+id/tableNameTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="8dp"
android:text="Name" />
<TextView
android:id="#+id/tableNameDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingEnd="8dp"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/priceUSDTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tablePriceUSDTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="8dp"
android:text="Price (USD)" />
<TextView
android:id="#+id/tablePriceUSDDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingEnd="8dp"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/priceBTCTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/lightGray">
<TextView
android:id="#+id/tablePriceBTCTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="8dp"
android:text="Price (BTC)" />
<TextView
android:id="#+id/tablePriceBTCDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingEnd="8dp"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/volUSDTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tableVolUSDTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="8dp"
android:text="24h Volume" />
<TextView
android:id="#+id/tableVolUSDDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingEnd="8dp"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/mktCapUSDTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/lightGray">
<TextView
android:id="#+id/tableMktCapTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="8dp"
android:text="Market Cap" />
<TextView
android:id="#+id/tableMktCapDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingEnd="8dp"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/availableSupplyTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tableAvailableSupplyTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="8dp"
android:text="Available Supply" />
<TextView
android:id="#+id/tableAvailableSupplyDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingEnd="8dp"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/totalSupplyTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/lightGray">
<TextView
android:id="#+id/tableTotalSupplyTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="8dp"
android:text="Total Supply" />
<TextView
android:id="#+id/tableTotalSupplyDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingEnd="8dp"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/maxSupplyTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tableMaxSupplyTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="8dp"
android:text="Max Supply" />
<TextView
android:id="#+id/tableMaxSupplyDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingEnd="8dp"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:id="#+id/changeTitlesTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/lightGray">
<TextView
android:id="#+id/table1hrChangeTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="8dp"
android:text="Change 1hr"
android:textAlignment="center" />
<TextView
android:id="#+id/table24hrChangeTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingStart="8dp"
android:text="Change 24hr"
android:textAlignment="center" />
<TextView
android:id="#+id/tableWeekChangeTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:paddingStart="8dp"
android:text="Change 7d"
android:textAlignment="center" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/lightGray">
<TextView
android:id="#+id/table1hrChangeDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingEnd="8dp"
android:textAlignment="center"
android:textStyle="bold" />
<TextView
android:id="#+id/table24hrChangeDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingEnd="8dp"
android:textAlignment="center"
android:textStyle="bold" />
<TextView
android:id="#+id/tableWeekChangeDataTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:paddingEnd="8dp"
android:textAlignment="center"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</android.support.constraint.ConstraintLayout>

How to move buttons to bottom of screen?

Before I recently updated Android Studio, I had the buttons aligned to the bottom of the screen. Whenever I try to use android:layout:_alignParentBottom inside of a relative layout that layout param apparently does not exist now.
The left is how it looked before and the right is how it looks now
Main Activity XML code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical"
tools:context="techercise.onerepmaxcalculator.MainActivity">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/bannerAd"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
ads:adSize="BANNER"
ads:adUnitId="#+id/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="vertical">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:fontFamily="sans-serif-smallcaps"
android:gravity="center"
android:text="#string/Formulas"
android:textColor="#EEFF41"
android:textSize="48sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/textView3"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="#android:color/darker_gray"/>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:layout_margin="24dp"
android:textAlignment="center"
android:textColor="#00C853"
android:textSize="44sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-smallcaps"
android:gravity="center_horizontal"
android:text="#string/weight"
android:textColor="#000000"
android:textSize="24sp" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:ems="2"
android:inputType="number"
android:textColor="#000000"
android:textSize="24sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-smallcaps"
android:gravity="center_horizontal"
android:text="#string/reps"
android:textColor="#000000"
android:textSize="24sp" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:ems="2"
android:inputType="number"
android:textColor="#000000"
android:textSize="24sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="buttonSubmit"
android:text="#string/submitBtnText"
android:textColor="#00C853"
android:textSize="16sp" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="clearSubmit"
android:text="#string/clearBtnText"
android:textColor="#F44336"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
Use RelativeLayout instead of ScrollView if you don't have a view hierarchy that can be scrolled.
A ScrollView is a FrameLayout, meaning you should place one child in
it containing the entire contents to scroll;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical"
tools:context="techercise.onerepmaxcalculator.MainActivity">
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/bannerAd"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
ads:adSize="BANNER"
ads:adUnitId="#+id/banner_ad_unit_id"></com.google.android.gms.ads.AdView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="vertical">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:fontFamily="sans-serif-smallcaps"
android:gravity="center"
android:text="#string/Formulas"
android:textColor="#EEFF41"
android:textSize="48sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/textView3"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:layout_margin="24dp"
android:textAlignment="center"
android:textColor="#00C853"
android:textSize="44sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-smallcaps"
android:gravity="center_horizontal"
android:text="#string/weight"
android:textColor="#000000"
android:textSize="24sp" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:ems="2"
android:inputType="number"
android:textColor="#000000"
android:textSize="24sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-smallcaps"
android:gravity="center_horizontal"
android:text="#string/reps"
android:textColor="#000000"
android:textSize="24sp" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:ems="2"
android:inputType="number"
android:textColor="#000000"
android:textSize="24sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="buttonSubmit"
android:text="#string/submitBtnText"
android:textColor="#00C853"
android:textSize="16sp" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="clearSubmit"
android:text="#string/clearBtnText"
android:textColor="#F44336"
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>
Note:
- To move the layout when keyboard comes up, add the following attribute to your activity inside AndroidManifest.xml file:
android:windowSoftInputMode="adjustResize"
you can layout like that:
RelativeLayout in overall
ScrollView for your contents Layout
(LinearLayout, RelativeLayout...) at the bottom button
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:background="#color/COLOR_BG_MENU_PARENT_DEFAULT"
android:orientation="vertical" />
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center"
android:orientation="horizontal"
android:id="#+id/llButton"
android:background="#color/COLOR_CHART_BLUE"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="Button 02" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Button 01" />
</LinearLayout>
Here is the correct code: I removed the ScrollView completely.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<com.google.android.gms.ads.AdView
android:id="#+id/bannerAd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-8808093751237190/1348767274">
</com.google.android.gms.ads.AdView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bannerAd"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:fontFamily="sans-serif-smallcaps"
android:gravity="center"
android:text="#string/Formulas"
android:textColor="#EEFF41"
android:textSize="48sp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/textView3"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="#android:color/darker_gray">
</View>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:layout_margin="24dp"
android:textAlignment="center"
android:textColor="#00C853"
android:textSize="44sp"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-smallcaps"
android:gravity="center_horizontal"
android:text="#string/weight"
android:textColor="#000000"
android:textSize="24sp"/>
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:ems="2"
android:inputType="number"
android:textColor="#000000"
android:textSize="24sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-smallcaps"
android:gravity="center_horizontal"
android:text="#string/reps"
android:textColor="#000000"
android:textSize="24sp"/>
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:ems="2"
android:inputType="number"
android:textColor="#000000"
android:textSize="24sp"/>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:id="#+id/button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="buttonSubmit"
android:text="#string/submitBtnText"
android:textColor="#00C853"
android:textSize="16sp"/>
<Button
android:id="#+id/button2"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="clearSubmit"
android:text="#string/clearBtnText"
android:textColor="#F44336"
android:textSize="16sp"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

Categories

Resources