Change activity or scroll activity when keyboard appear - android

I have an recycleview in the end of activity but i want,when keyboard appear on click field_comment_form
the activity goes up to the EditText and only EditText and recycleview will be seen
I already tried many ways including
windowSoftInputMode:adjustResize
my code of xml is below:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="3dp">
<android.support.v7.widget.CardView
android:id="#+id/post_text_layout_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="1dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<include
android:id="#+id/post_author_layout"
layout="#layout/include_post_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<LinearLayout
android:id="#+id/star_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/post_author_layout"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/post_author_layout"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/star_cmnt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:background="?attr/selectableItemBackground"
android:src="#drawable/ic_create_black_24dp" />
<TextView
android:id="#+id/post_num_stars_cmnt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#000"
android:textStyle="bold"
tools:text="7" />
</LinearLayout>
<include
layout="#layout/include_post_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/post_author_layout"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:id="#+id/comment_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/post_text_layout_card"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="5dp"
android:background="#drawable/cmnt_post_box_back"
android:orientation="horizontal"
android:weightSum="1.0">
<EditText
android:id="#+id/field_comment_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:breakStrategy="balanced"
android:fitsSystemWindows="true"
android:gravity="top"
android:hint="Write a comment..."
android:maxLines="2" />
<Button
android:id="#+id/button_post_comment"
style="#style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="Post" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_comments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/comment_form"
tools:listitem="#layout/item_comment" />
</RelativeLayout>`
screenshot is here

Related

Fragment layout is not scrolling above keyboard when soft keyboard pop ups

I have one fragment whose layout i want to show above keyboard when softkeyboard opens up. The layout is:
<?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:animateLayoutChanges="true"
android:background="#drawable/ic_bg_splash"
android:fitsSystemWindows="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2">
<ImageButton
android:id="#+id/previous"
android:layout_width="37.5dp"
android:layout_height="37.5dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:background="#drawable/left"
android:padding="7dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="12dp">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="7dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="7dp"
android:layout_marginRight="12dp"
android:layout_marginBottom="7dp"
android:orientation="vertical">
<ImageView
android:id="#+id/subCat"
android:layout_width="157.5dp"
android:layout_height="157.5dp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="50dp"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="12dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito"
android:paddingLeft="20dp"
android:text="#string/enter_answer"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="13sp" />
<LinearLayout
android:layout_width="262.5dp"
android:layout_height="52.5dp"
android:layout_marginTop="7dp"
android:background="#drawable/answer_bg"
android:orientation="horizontal">
<EditText
android:id="#+id/answer"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="8"
android:background="#null"
android:fontFamily="#font/nunito"
android:inputType="textNoSuggestions"
android:maxLines="1"
android:padding="7dp"
android:textColor="#android:color/white"
android:textSize="15sp" />
<ImageView
android:id="#+id/wrong_answer"
android:layout_width="27.5dp"
android:layout_height="28dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:src="#drawable/red_cross"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:layout_marginBottom="27dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito"
android:text="#string/reset"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="14.3sp" />
<TextView
android:id="#+id/submit_ans"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:background="#drawable/white_rounded"
android:fontFamily="#font/nunito_semibold"
android:paddingLeft="17dp"
android:paddingTop="7dp"
android:paddingRight="17dp"
android:paddingBottom="7dp"
android:text="#string/submit"
android:textAllCaps="true"
android:textColor="#color/lineColor"
android:textSize="14.3sp" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2">
<ImageButton
android:id="#+id/next"
android:layout_width="37.5dp"
android:layout_height="37.5dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="22dp"
android:background="#drawable/right" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/write_dark"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#70000000"
android:elevation="10dp"
android:visibility="gone">
<ImageView
android:id="#+id/write_success"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="10dp" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I have tried by setting windowssoftinputmode to adjustResize in manifest and also using fitsystemwindows to true in the fragment parent layout but still it is not working and using scrollview as parent layout instead of relativelayout. So please suggest me any workaround for this issue.
Edit: Added below activity.xml layout:
Below is the host activity layout:
<?xml version="1.0" encoding="utf-8"?>
<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:background="#drawable/language_bg"
android:orientation="vertical"
tools:context=".home.HomeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bottom_rounded">
<RelativeLayout
android:id="#+id/taskBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_gravity="center_vertical"
android:layout_weight="1.7"
android:paddingLeft="30dp"
android:paddingTop="5dp">
<ImageView
android:layout_width="143dp"
android:layout_height="56dp"
android:layout_gravity="left|center_vertical"
android:src="#drawable/hello_logo" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/learn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="33dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:src="#drawable/learn_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="#string/learn"
android:textColor="#color/lineColor"
android:textSize="11sp" />
<View
android:id="#+id/learn_bar"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:background="#color/lineColor" />
</LinearLayout>
<LinearLayout
android:id="#+id/practice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="42dp"
android:layout_height="28dp"
android:src="#drawable/practice_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="#string/practice"
android:textColor="#color/lineColor"
android:textSize="11sp" />
<View
android:id="#+id/practice_bar"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:background="#color/lineColor"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:layout_marginRight="30dp"
android:layout_weight="1.3"
android:gravity="right"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/unlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="26.5dp"
android:layout_height="32dp"
android:src="#drawable/unlock_blue" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="#string/unlock"
android:textColor="#color/lineColor"
android:textSize="11dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:gravity="center_horizontal|bottom"
android:orientation="vertical">
<ImageView
android:layout_width="33dp"
android:layout_height="30dp"
android:layout_marginTop="2dp"
android:src="#drawable/language" />
<TextView
android:id="#+id/language_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:text="#string/lang"
android:textAllCaps="true"
android:textColor="#color/lineColor"
android:textSize="11dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/appbar_practice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimaryDark"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="12dp"
android:visibility="gone">
<LinearLayout
android:id="#+id/read_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="23.5dp"
android:layout_height="17.5dp"
android:background="#drawable/icon_read" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:fontFamily="#font/nunito_semibold"
android:text="#string/read"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="13sp" />
</LinearLayout>
<View
android:id="#+id/read_bar"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="12dp"
android:background="#android:color/white" />
</LinearLayout>
<LinearLayout
android:id="#+id/speak_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="16.5dp"
android:layout_height="21.5dp"
android:background="#drawable/icon_speak" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:fontFamily="#font/nunito_semibold"
android:text="#string/speak"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="13sp" />
</LinearLayout>
<View
android:id="#+id/speak_bar"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="12dp"
android:background="#android:color/white"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="#+id/listen_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="18.5dp"
android:layout_height="18.5dp"
android:background="#drawable/icon_listen" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:fontFamily="#font/nunito_semibold"
android:text="#string/listen"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="13sp" />
</LinearLayout>
<View
android:id="#+id/listen_bar"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="12dp"
android:background="#android:color/white"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="#+id/write_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="17dp"
android:layout_height="19dp"
android:background="#drawable/icon_write" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:fontFamily="#font/nunito_semibold"
android:text="#string/write"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="13sp" />
</LinearLayout>
<View
android:id="#+id/write_bar"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="12dp"
android:background="#android:color/white"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Try to put your scrollView into relative Layout.
After commenting this from my activity onCreate() it started working:
this.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)

How to scroll an EditText to the very top of the layout?

So I have this layout with some ChipsInput inside a scrollview and I simply want these to go to the very top when the keyboard is activated
I've tried to change windowSoftInputMode to adjustPan and others but it does not make it to go to the very top, just doesn't cover it.
Here's my xml layout
<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:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background1"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<LinearLayout
android:id="#+id/layoutImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#color/colorPrimary"
android:elevation="12dp"
android:orientation="horizontal"
android:padding="10dp"
tools:targetApi="lollipop">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="3dp"
android:layout_weight="1"
android:fontFamily="#font/quattrocento"
android:gravity="left"
android:text="#string/profile"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#color/textColor1"
tools:ignore="RtlHardcoded" />
<ImageButton
android:id="#+id/btUpdate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="#color/colorPrimary"
android:src="#drawable/arrow_right_icon" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:orientation="vertical"
tools:targetApi="o">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/quattrocento"
android:gravity="center"
android:text="#string/gallery"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="#color/textColor2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp"
android:baselineAligned="false">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageButton
android:id="#+id/close1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_close"
android:background="#color/white"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:elevation="7dp"
android:visibility="invisible"/>
<ImageButton
android:id="#+id/add1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_add"
android:background="#color/white"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:elevation="7dp"/>
<ImageView
android:id="#+id/photo1"
android:layout_width="match_parent"
android:layout_height="115dp"
android:layout_marginHorizontal="5dp"
android:background="#drawable/rounded_rect_primary_dark"
android:elevation="5dp"
android:scaleType="fitXY"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageButton
android:id="#+id/close2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_close"
android:background="#color/white"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:elevation="7dp"
android:visibility="invisible"/>
<ImageButton
android:id="#+id/add2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_add"
android:background="#color/white"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:elevation="7dp"/>
<ImageView
android:id="#+id/photo2"
android:layout_width="match_parent"
android:layout_height="115dp"
android:layout_marginHorizontal="5dp"
android:background="#drawable/rounded_rect_primary_dark"
android:elevation="5dp"
android:scaleType="fitXY" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageButton
android:id="#+id/close3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_close"
android:background="#color/white"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:elevation="7dp"
android:visibility="invisible"/>
<ImageButton
android:id="#+id/add3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_add"
android:background="#color/white"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:elevation="7dp"/>
<ImageView
android:id="#+id/photo3"
android:layout_width="match_parent"
android:layout_height="115dp"
android:layout_marginHorizontal="5dp"
android:background="#drawable/rounded_rect_primary_dark"
android:elevation="5dp"
android:scaleType="fitXY"/>
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginHorizontal="12dp"
android:layout_marginVertical="5dp"
android:background="#color/black" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/quattrocento"
android:text="#string/about_me"
android:textColor="#color/textColor2"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/white">
<EditText
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#color/white"
android:focusable="true"
android:maxLength="500"
android:inputType="text"
android:importantForAutofill="no"
android:autofillHints="no"
tools:ignore="LabelFor" />
<TextView
android:id="#+id/caracCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/quattrocento"
android:text="500"
android:textColor="#color/black"
android:textSize="16sp"
android:layout_gravity="end" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/quattrocento"
android:text="#string/interest1"
android:textColor="#color/textColor2"
android:textSize="20sp"
android:layout_gravity="center"
android:gravity="center"/>
<Spinner
android:id="#+id/categories1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:background="#color/colorPrimary" />
</LinearLayout>
<com.pchmn.materialchips.ChipsInput
android:id="#+id/chipsInput1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/white"
android:elevation="3dp"
android:focusable="false"
app:chip_deletable="true"
app:chip_hasAvatarIcon="false"
app:hint="#"
app:chip_backgroundColor="#color/colorPrimary"
app:chip_deleteIconColor="#color/black"
app:chip_labelColor="#color/black"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/quattrocento"
android:text="#string/interest2"
android:textColor="#color/textColor2"
android:textSize="20sp"
android:layout_gravity="center"
android:gravity="center"/>
<Spinner
android:id="#+id/categories2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:background="#color/colorPrimary" />
</LinearLayout>
<com.pchmn.materialchips.ChipsInput
android:id="#+id/chipsInput2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/white"
android:elevation="3dp"
android:focusable="false"
app:chip_deletable="true"
app:chip_hasAvatarIcon="false"
app:hint="#"
app:chip_backgroundColor="#color/colorPrimary"
app:chip_deleteIconColor="#color/black"
app:chip_labelColor="#color/black" />
<Button
android:id="#+id/btLogout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="25dp"
android:background="#color/colorPrimary"
android:elevation="12dp"
android:fontFamily="#font/quattrocento"
android:text="#string/logout"
android:textSize="20sp"
android:onClick="logout"
tools:targetApi="lollipop"
android:textColor="#color/black"/>
</LinearLayout>
</ScrollView>
I simply need it to be sent to the very top of the layout so my filterable list will appear when the user start to type.
You can use CoordinatorLayout as your root and NestedScrolView in it .
CoordinatorLayout as root reacts to keyboard and scrolls your layout to the top of your phone with assistant of NestedScrollView which your NestedScrollView includes your layout code .
To put the issue into perspective view
CoordinaterLayout > NestedScrolView > yourLayout
Change your layout XMl like code below
<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">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background1"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<!-- rest of your layout xml code-->
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

how to redirect on edittext when click on icon or image?

Following is my xml file. I want that when I click imgDescAddCity it will redirect on next EditText which is txtDescAddCity. It is like a WhatsApp status when we click on edit or change status icon it can allow writing new status in EditText same as hear. I want that when I click on imgDescAddCity icon cursor will redirect on txtDescAddCity EditText.
<include
android:id="#+id/include"
layout="#layout/header_new_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/include"
android:background="#color/backgroundLayout"
android:orientation="vertical"
android:weightSum="5">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<EditText
android:id="#+id/txtCityNameAddCity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="City name"
android:inputType="textPersonName" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="#+id/textView141"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1.75"
android:text="Description"
android:textStyle="bold" />
<ImageView
android:id="#+id/imgDescAddCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="0.25"
app:srcCompat="#drawable/ic_border_color_black" />
</LinearLayout>
<EditText
android:id="#+id/txtDescAddCity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:hint="description here" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#color/backgroundColor"
android:orientation="horizontal"
android:weightSum="2">
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.75"
android:background="#null"
android:layout_gravity="center"
android:entries="#array/addcity" />
<ImageView
android:id="#+id/imageView82"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="0.25"
app:srcCompat="#drawable/search_magnifying" />
</LinearLayout>
<EditText
android:id="#+id/txtSeasonToVisitAddCity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Best season to visit"
android:inputType="textPersonName" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1.75"
android:text="City photo" />
<ImageView
android:id="#+id/imgAttachAddCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_weight="0.25"
app:srcCompat="#drawable/attach" />
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewAddCityImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="0dp"
android:orientation="horizontal" />
<TextView
android:id="#+id/addCity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/lightBlue"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="city"
android:textAlignment="center"
android:textColor="#color/backgroundColor" />
</LinearLayout>
</ScrollView>
</LinearLayout>
as per my above comment
use requestFocus method on edittext
edittext.requestFocus();
try this tutorial.

After fragment replace fragment view not scrollable

In the first fragmentA there is a RecyclerView. If clicked RecyclerView item, fragmentA replaced with fragmentB. For the first time when the open fragmentA it's work correctly. So when I click RecyclerView item, fragmentA replaced with fragmentB, but fragmentB not scrolling. Then when I back (by BackStack) to fragmentA, I found it also not scrollable, although it's was a scrollable before replacing with fragmentB. fragmentB also has RecyclerView's in horizontal stage. I can't understand what is the problem. Any idea,advice, help will be important for me. Thanks
MainActivity where I do replacing of fragments by listener
#Override
public void onObjectItemClicked(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).replace(R.id.flContent, fragment).addToBackStack(null).commit();
fragmentManager.executePendingTransactions();
}
MainActivity layout
<RelativeLayout
android:layout_marginTop="?android:attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="#+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
FragmentA layout
<?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">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:visibility="gone"
android:id="#+id/mapFragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/objects_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
FragmentB layout
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/object_img_rl"
android:layout_width="match_parent"
android:layout_height="220dp"
>
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/object_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/dark_gradient"
/>
<RelativeLayout
android:visibility="gone"
android:id="#+id/aksia_img"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="#drawable/image_aksia" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:rotation="270"
android:text="#string/aksia"
android:textColor="#color/colorWhite" />
</RelativeLayout>
<ImageView
android:visibility="gone"
android:id="#+id/imgHalal"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
app:srcCompat="#drawable/halal" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="end"
android:maxLines="1"
android:text="Ағайын"
android:textColor="#color/colorWhite"
android:textSize="19sp" />
<LinearLayout
android:id="#+id/time_ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_centerInParent="true"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<ImageView
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_gravity="center"
android:src="#drawable/ic_green_circle" />
<TextView
android:id="#+id/work_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:ellipsize="end"
android:maxLines="1"
android:text="мкр Айнабулак 4, дом 1"
android:textColor="#color/colorWhite"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/time_ll"
android:layout_centerInParent="true"
android:layout_gravity="end"
android:layout_marginTop="5dp"
android:maxLines="1"
android:text="мкр Айнабулак 4, дом 1"
android:textColor="#color/colorWhite"
android:textSize="12sp" />
<TextView
android:layout_marginTop="30dp"
android:id="#+id/object_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorWhite"
android:textSize="15sp"
android:layout_alignParentTop="true"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:visibility="gone"
android:id="#+id/conOval"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="180dp"
android:background="#drawable/oval_fragment_detail">
<TextView
android:id="#+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:gravity="center"
android:text="5/5"
android:textColor="#color/colorAccent"
android:textSize="25sp" />
</RelativeLayout>
<LinearLayout
android:id="#+id/blok_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/object_img_rl"
android:layout_marginEnd="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="35dp"
android:orientation="vertical">
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/fragment_detail_text_color"
android:textSize="15sp" />
<android.support.v7.widget.RecyclerView
android:visibility="gone"
android:layout_gravity="center_horizontal"
android:id="#+id/kitchen_recycler_view"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginTop="20dp"
android:background="#fff" />
<android.support.v7.widget.RecyclerView
android:visibility="gone"
android:layout_gravity="center_horizontal"
android:id="#+id/service_recycler_view"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_marginTop="20dp"
android:background="#fff" />
<LinearLayout
android:visibility="gone"
android:id="#+id/con_aksia"
android:layout_width="match_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:background="#drawable/lynear_layout_border"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="#+id/aksia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/aksia"
android:textColor="#color/fragment_detail_text_color"
android:textSize="13sp" />
<TextView
android:id="#+id/aksia_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Акция контент"
android:textColor="#color/fragment_detail_text_color"
android:textSize="12sp" />
</LinearLayout>
<Button
android:id="#+id/use_aksia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:background="#color/colorAccent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="#string/use_aksia"
android:textColor="#color/colorWhite"
android:textSize="14sp" />
</LinearLayout>
<TextView
android:id="#+id/phone1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColor="#4A90E2"
android:textSize="14sp" />
<TextView
android:id="#+id/phone2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColor="#4A90E2"
android:textSize="14sp" />
<TextView
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColor="#4A90E2"
android:textSize="14sp" />
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColor="#color/fragment_detail_text_color"
android:textSize="14sp" />
<TextView
android:id="#+id/work_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColor="#color/fragment_detail_text_color"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/blok_two"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="#+id/blok_one"
android:layout_marginTop="25dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/colorWhite">
<Button
android:id="#+id/btnMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/button_border"
android:text="#string/menu"
android:textAllCaps="false"
android:textColor="#000000"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/colorWhite">
<Button
android:id="#+id/btnBron"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/button_border"
android:text="#string/bron"
android:textAllCaps="false"
android:textColor="#000000"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/blok_three"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/blok_two"
android:background="#F5F4F4"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp">
<ImageButton
android:id="#+id/imgInsta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#F5F4F4"
/>
<ImageButton
android:id="#+id/imgWapp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#F5F4F4"
/>
<ImageButton
android:id="#+id/imgFb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#F5F4F4"
/>
<ImageButton
android:id="#+id/imgVk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#F5F4F4"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/blok_four"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/blok_three"
android:layout_margin="25dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gallery"
android:textColor="#color/fragment_detail_text_color"
android:textSize="14sp" />
<android.support.v7.widget.RecyclerView
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:layout_marginTop="10dp"
android:id="#+id/gallery_recycler_view"
android:layout_width="match_parent"
android:layout_height="160dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="170dp"
android:orientation="vertical"
android:layout_below="#+id/blok_four"
android:layout_marginBottom="25dp">
</LinearLayout>
<LinearLayout
android:background="#FFFFFF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/comment_block"
android:orientation="vertical"
android:padding="25dp"
android:layout_below="#+id/map"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/comments"
android:textColor="#color/fragment_detail_text_color"
android:textSize="14sp" />
<android.support.v7.widget.RecyclerView
android:layout_marginTop="10dp"
android:id="#+id/comment_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/btnShowAllComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/show_all_comments"
android:textAllCaps="false"
android:layout_gravity="center_horizontal"
android:textColor="#4A90E2"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:theme="#style/buttonTransparentStyle"
style="?android:attr/borderlessButtonStyle"
/>
<Button
android:id="#+id/btnAddComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_selector_custom"
android:theme="#style/buttonTransparentStyle"
android:text="#string/add_comments"
android:textAllCaps="false"
android:textSize="16sp"
android:textColor="#4A90E2"
android:layout_gravity="center_horizontal"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:layout_marginTop="10dp"
/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
In second fragment you are using recycler view inside scroll view which can cause scrolling issue. Replace scrollview by nestedscrollview which is avaiable in support.v4.widget library. and call this on recylerview recyclerView.setNestedScrollingEnabled(false);. Then recyler view will work properly inside nested scrollview

3 equal height rows in a ScrollView

Here is my layout XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#mipmap/banner" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:id="#+id/row2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 1"
android:textColor="#color/darkBlue"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyRecipes"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAll1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:layout_below="#id/row2" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:id="#+id/row3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 2"
android:textColor="#color/darkBlue"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyFavorites"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAllFavorites"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:layout_below="#id/row3" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
As you can see from my layout, the outer LinearLayout contains 3 RelativeLayout which all have layout_weight equals to 1 and the LinearLayout has weightSum equal to 3.
However, the behavior of the current layout is: The 1st RelativeLayout shared very little space (around 10%) and the 2nd & 3rd RelativeLayout shared 45% of height.
How can I make them equally shared the height?
Add to below attributes to ScrollView
android:layout_centerVertical="true"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
Check layout below
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#mipmap/banner" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="#+id/row2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 1"
android:textColor="#color/blue_360"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyRecipes"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAll1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row2"
android:paddingBottom="5dp"
android:paddingTop="5dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="#+id/row3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 2"
android:textColor="#color/blue_360"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyFavorites"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAllFavorites"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row3"
android:paddingBottom="5dp"
android:paddingTop="5dp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Because your using scrollview you need to fill your view port to make the scroll view occupy the whole screen
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"/>
//..... your other code here
</ScrollView>

Categories

Resources