Android ScrollView not displaying child - android

I am beginner to android. I stuck at a problem that scrollview not displaying full content.It is clipping some content.
Root element is constraint layout.
demo string resource contains lots of dummy text only. whole string is not displaying only part of string is displaying. please help me to solve this issue.
<androidx.constraintlayout.widget.ConstraintLayout
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">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/mMainAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/mMainToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/color_main_appbar"
android:elevation="2dp"
android:gravity="start"
app:popupTheme="#style/Theme.MaterialComponents.Light">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_main_bg"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.google.android.material.textview.MaterialTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="#font/pacifico"
android:text="#string/app_name"
android:textAlignment="center"
android:textColor="#color/color_main_app_name"
android:textSize="22sp" />
<ImageButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="8dp"
android:background="#color/color_main_bg"
android:contentDescription="#string/main_search_des"
android:foregroundGravity="right"
android:padding="8dp"
app:srcCompat="#drawable/ic_search_32" />
</LinearLayout>
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fillViewport="true"
android:padding="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/mMainAppBar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/demo"
/>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

I have used the above XML and it is showing all the text properly.
Check if you are setting any layout params inside your activity dynamically
Additionaly you can try using android:fitSystemWindows="true"
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fillViewport="true"
android:padding="10dp"
app:layout_constraintEnd_toEndOf="parent"
android:fitsSystemWindows="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/mMainAppBar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/demo"
/>
</LinearLayout>
</ScrollView>

You can add paddingBottom inside LinearLayout :
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fillViewport="true"
android:padding="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/mMainAppBar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
//android:paddingBottom="35dp" Add here
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/demo"
/>
</LinearLayout>
</ScrollView>

Related

add version of app at bottom navigation view is not displayed properly

As a lot of people are probably trying to do it, I am trying to add a footer to a navigation view. I did this:
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/background"
android:clipToPadding="true"
app:headerLayout="#layout/layout_nav_header"
app:menu="#menu/navigation_menu">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="24dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:gravity="left"
android:text="#string/appVersion"/>
<TextView
android:id="#+id/buildInfoTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</com.google.android.material.navigation.NavigationView>
This working fine but not in 2 cases: small screen because the linearlayout overlap the menu and also if the keyboard is popped up, it move the layout.
Any idea how to make sure that the linear layout with the app version stick to the bottom of the navigation or also below the menu item so it's not overlapping on small screen.
Thanks
Try this once
Note change widget values and parameters as per your requirements.
OPTION 1-
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:headerLayout="#layout/content_main"
app:layout_constraintBottom_toTopOf="#+id/linearLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="#menu/menu_main" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="start|center"
android:text="#string/app_name" />
<TextView
android:id="#+id/buildInfoTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="start|center"
android:text="#string/app_name" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
OPTION 2-
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/linear"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:headerLayout="#layout/content_main"
app:menu="#menu/menu_main" />
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="start|center"
android:text="#string/app_name" />
<TextView
android:id="#+id/buildInfoTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="start|center"
android:text="#string/app_name" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

linearlayout is not getting displayed below recyclerview

in my layout i have recyclerview of product listing..below that im displaying total price in linearlayout ...but on scroll linearlayout is not displaying
sceneorio of my code:
1--> when i have one item on recyclerview -->linearlayout displays fine
2--> when i have more items on recyclerview -->on scrolling down linearlayout cant be seen(linear layout is not displaying)
need help in second sceneorio...thanks in advance
Following here is code xml:--
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relative">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:collapseIcon="#drawable/ic_arrow_back_black_24dp"
android:id="#+id/toolbartable"
android:background="#color/colorPrimaryDark">
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/relative"
android:id="#+id/nest"
android:scrollbars="vertical">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_below="#id/relative"
android:layout_height="wrap_content"
android:id="#+id/recyleview"/>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="#+id/linearlayoutorder"
android:layout_below="#id/nest"
android:orientation="horizontal"
android:weightSum="2"
android:background="#drawable/border"
android:backgroundTintMode="#color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOTAL"
android:layout_gravity="center"
android:layout_weight="1"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/totalidcost"
android:layout_gravity="right|center"
android:textAlignment="textEnd"
tools:ignore="RtlCompat"></TextView>
</LinearLayout>
</RelativeLayout>
Updated code:--
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relative">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:collapseIcon="#drawable/ic_arrow_back_black_24dp"
android:id="#+id/toolbartable"
android:background="#color/colorPrimaryDark">
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/nest"
android:scrollbars="vertical"
android:layout_below="#id/relative">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:id="#+id/recyleview"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="#+id/linearlayoutorder"
android:orientation="horizontal"
android:weightSum="2"
android:background="#drawable/border"
android:backgroundTintMode="#color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOTAL"
android:layout_gravity="center"
android:layout_weight="1"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/totalidcost"
android:layout_gravity="right|center"
android:textAlignment="textEnd"
tools:ignore="RtlCompat"></TextView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
error getting--:Caused by: android.view.InflateException: Binary XML file line #34: ScrollView can host only one direct child
`Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child`
need help
following solution worked for me:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relative">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:collapseIcon="#drawable/ic_arrow_back_black_24dp"
android:id="#+id/toolbartable"
android:background="#color/colorPrimaryDark">
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/nest"
android:scrollbars="vertical"
android:layout_below="#id/relative">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:id="#+id/recyleview"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="#+id/linearlayoutorder"
android:layout_below="#id/recyleview"
android:orientation="horizontal"
android:weightSum="2"
android:background="#drawable/border"
android:backgroundTintMode="#color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOTAL"
android:layout_gravity="center"
android:layout_weight="1"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/totalidcost"
android:layout_gravity="right|center"
android:textAlignment="textEnd"
tools:ignore="RtlCompat"></TextView>
</LinearLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
You haven't added weightSum and orientation values ​​for LinearLayout.
Source
You can use a NestedScrollView instead of the ScrollView. And also put your RecyclerView as well as the LinearLayout inside the NestedScrollView. And enable android:nestedScrollingEnabled=true. Should work for you.
<NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled=true>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyleview"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/linearlayoutorder"
app:layout_constraintTop_toBottomOf="#id/relative" />
<LinearLayout
android:id="#+id/linearlayoutorder"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#000000"
android:backgroundTintMode="#color/colorPrimary"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="TOTAL" />
<TextView
android:id="#+id/totalidcost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_weight="1"
android:textAlignment="textEnd"
tools:ignore="RtlCompat" />
</LinearLayout>
</LinearLayout>
And in your java class where you have your recyclerview set recyclerView.setNestedScrollingEnabled(true or false);
Use ConstraintLayout like this way, Here is full xml code what you need
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<RelativeLayout
android:id="#+id/relative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbartable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimaryDark"
app:collapseIcon="#drawable/back" />
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyleview"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/linearlayoutorder"
app:layout_constraintTop_toBottomOf="#id/relative" />
<LinearLayout
android:id="#+id/linearlayoutorder"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#000000"
android:backgroundTintMode="#color/colorPrimary"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="TOTAL" />
<TextView
android:id="#+id/totalidcost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_weight="1"
android:textAlignment="textEnd"
tools:ignore="RtlCompat" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Align button for right in the middle of TextView

I want to align button for right in the middle of TextView like WhatsApp. Android studio's layout preview screen is showing right but at phone it is not align middle of TextView, align bottom of screen.
No problem with fragment alone but when fragment inside activity, problem occurs. I understand that my activity layout is wrong.
How can I align send button?
Whatsapp button:
My button at Android Studio preview:
My button at phone:
my fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#color/colorBlue"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="#+id/userNames"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:padding="10dp"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:text="Hello Nilu Pilu"
android:textColor="#color/colorGreen" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:contentDescription="#null"
android:src="#drawable/ic_log_out" />
</RelativeLayout>
my activity layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#color/colorPrimary"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
app:tabMode="scrollable">
<androidx.appcompat.widget.SearchView
android:id="#+id/search_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:contentDescription="#null"
android:iconifiedByDefault="false"
android:tint="#color/white"
app:defaultQueryHint="#string/searchForName"
app:iconifiedByDefault="false"
app:queryHint="#string/searchForName"
app:srcCompat="#drawable/ic_search_24" />
</androidx.appcompat.widget.Toolbar>
<LinearLayout
android:id="#+id/share_list_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="MergeRootFrame" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
NO need to use nested RelativeLayout you can achieve it only using single RelativeLayout
Try this using RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#color/colorBlue"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="#+id/userNames"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:padding="10dp"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:text="Hello Nilu Pilu"
android:textColor="#color/colorGreen" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:contentDescription="#null"
android:src="#drawable/ic_log_out" />
</RelativeLayout>
Try this using ConstraintLayout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/colorBlue"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/userNames"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:padding="10dp"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:text="Hello Nilu Pilu"
android:textColor="#color/colorGreen"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:contentDescription="#null"
android:src="#drawable/ic_log_out"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
OUTPUT
I suggest use ConstraintLayout layout instead of RelativeLayout and here is your code with ConstraintLayout, which will work perfectly.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/emptyListColor"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#+id/bottomView"
android:layout_height="0dp" />
<RelativeLayout
android:id="#+id/bottomView"
android:layout_width="match_parent"
android:layout_height="40dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:padding="5dp">
<TextView
android:id="#+id/userNames"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start|center_vertical"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:padding="5dp"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:textColor="#color/white" />
</RelativeLayout>
<ImageView
android:id="#+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
app:layout_constraintTop_toTopOf="#+id/bottomView"
app:layout_constraintBottom_toTopOf="#+id/bottomView"
app:layout_constraintEnd_toEndOf="#+id/bottomView"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="#drawable/send_circle"
android:contentDescription="#null"
android:src="#drawable/attach_send2" />
</androidx.constraintlayout.widget.ConstraintLayout>

The Coordinator layout doesn't Scroll up for a specific position

I am facing this issue with coordinator layout about scrolling. For a specific position it wont scroll buy, After clicking on Add new button a list element gets added below. And if we scroll that item the coordinator layout behaves normally like expand and shrink. But when we try to scroll up by touching on the layout
main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/cord"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="#4a90e2"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="#4a90e2"
app:statusBarScrim="#4a90e2"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="120dp"
android:paddingBottom="40dp"
android:layout_gravity="center|top"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Suzuki Swift !"
android:textStyle="bold"
android:textColor="#android:color/white"
android:textSize="30dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:fontFamily="#font/latoregular"
android:text="Some Text to enter about swift."/>
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include
layout="#layout/test_one"/>
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="#drawable/man"
android:layout_gravity="center|top"
android:layout_marginTop="8dp"
android:elevation="10dp"
app:layout_behavior="#string/simple_view_behavior"
app:behavior_dependsOn="#+id/app_bar"
app:behavior_dependType="y"
app:behavior_dependTarget="-176dp"
app:behavior_targetX="16dp"
app:behavior_targetY="8dp"
app:behavior_targetWidth="40dp"
app:behavior_targetHeight="40dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:text="Review For Swift"
android:textSize="18dp"
android:elevation="10dp"
android:layout_marginLeft="72dp"
android:layout_marginTop="-100dp"
android:gravity="center_vertical"
android:textColor="#android:color/white"
android:alpha="0"
app:layout_behavior="#string/simple_view_behavior"
app:behavior_dependsOn="#+id/app_bar"
app:behavior_dependType="y"
app:behavior_dependTarget="-206dp"
app:behavior_targetY="0dp"
app:behavior_targetAlpha="1"/>
</android.support.design.widget.CoordinatorLayout>
Included Layout in main.xml i.e. test_one.xml
<?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"
android:id="#+id/relative_layout"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff">
<android.support.v7.widget.CardView
android:id="#+id/cardOne"
app:cardUseCompatPadding="true"
app:cardElevation="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/linear_layout"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/linearLoutTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/linearLoutOne"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ellipsize="end"
android:fontFamily="#font/latoregular"
android:maxLines="1"
android:text="Review For Swift add attributes below,"
android:textColor="#color/titleColor"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:background="#drawable/white_border_round"
android:fontFamily="#font/latolight"
android:hint="Eg: Looks,Speed"
android:padding="4dp"
android:paddingEnd="8dp"
android:paddingStart="8dp"
android:textColorHint="#color/titleColor"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="#+id/add_row_button"
app:layout_constraintHorizontal_bias="0.096"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/userName" />
<Button
android:id="#+id/add_row_button"
android:layout_width="100dp"
android:layout_height="35dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:layout_weight="2"
android:background="#color/titleColor"
android:fontFamily="#font/latobold"
android:onClick="addRow"
android:text="Add"
android:textColor="#color/white"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<com.example.android.uidesigns.XmlClasses.InsertionListView
android:id="#+id/listview"
android:nestedScrollingEnabled="true"
android:layout_below="#id/cardOne"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
list_item.xml
<android.support.v7.widget.CardView
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_height="wrap_content"
android:layout_width="match_parent"
app:cardElevation="4dp"
app:cardCornerRadius="4dp"
app:cardUseCompatPadding="true">
<android.support.constraint.ConstraintLayout
android:id="#+id/item_linear_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal">
<!--<de.hdodenhof.circleimageview.CircleImageView-->
<!--android:id="#+id/image_view"-->
<!--android:layout_width="80dp"-->
<!--android:layout_height="80dp"-->
<!--android:layout_marginBottom="8dp"-->
<!--android:layout_marginStart="18dp"-->
<!--android:layout_marginTop="8dp"-->
<!--android:gravity="center_vertical"-->
<!--android:src="#drawable/man"-->
<!--app:layout_constraintBottom_toBottomOf="parent"-->
<!--app:layout_constraintStart_toStartOf="parent"-->
<!--app:layout_constraintTop_toTopOf="parent" />-->
<TextView
android:id="#+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="center_vertical"
android:text="Hello"
android:textColor="#111"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
I have added a Gif to make my problem clear. Please take a look.
----->[gif for understanding]: https://i.stack.imgur.com/uSGfX.gif
Finally, I found the solution.
Rather than including the layout, I wrote it in the same file within NestedScrollView.
Somehow it worked. Thanks for the help.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>

SwipeRefreshLayout + another view

I have my layout setup as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="#layout/my_toolbar" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.my.SubView
android:id="#+id/my_list_subview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white" />
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:id="#+id/text_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/padding_medium"
android:layout_margin="#dimen/padding_medium"
android:text="Hello"
android:textSize="14sp"
android:maxLines="3"/>
</LinearLayout>
The problem is that the SwipeRefreshLayout takes up the entire screen and the textview doesn't show up at all.
The blue line in the above image is where the text view is. Is there anything I am missing? This seems to be so simple a problem, its ludicrous!
Image 2 in response to the answer by #Tomar
try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/my_toolbar"
android:id="#+id/top_layout"/>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_above="#+id/text_content"
android:layout_below="#+id/top_layout"
android:layout_height="wrap_content">
<com.my.SubView
android:id="#+id/my_list_subview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white" />
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:id="#+id/text_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/padding_medium"
android:layout_margin="#dimen/padding_medium"
android:text="Hello"
android:textSize="14sp"
android:layout_alignParentBottom="true"
android:maxLines="3"/>
</RelativeLayout>
As I mentioned above, I worked it out with ConstraintLayout as below. I do not know why I need to use a large bottom margin and padding in the swipe refresh layout for it to sit above the text. Without these, it doesn't work!
<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="wrap_content"
android:background="#color/white"
xmlns:app="http://schemas.android.com/apk/res-auto">
<include layout="#layout/toolbar"
android:id="#+id/my_toolbar"
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/padding_large"
android:paddingBottom="#dimen/padding_super_large"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar"
app:layout_constraintBottom_toTopOf="#+id/text_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<com.my.SubView
android:id="#+id/my_list_subview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/white"/>
</android.support.v4.widget.SwipeRefreshLayout>
<EditText
android:id="#+id/text_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/white"
android:hint="#string/write_message"
android:textSize="14sp"
android:maxLines="3"
android:padding="#dimen/padding_medium"
android:paddingLeft="#dimen/padding_large"
app:layout_constraintTop_toBottomOf="#+id/swipe_refresh"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:visibility="visible"
tools:layout_editor_absoluteX="0dp" />
</android.support.constraint.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/srl_reload_list"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView_openOrderList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Categories

Resources