I have a scroll view wrapping a LinearLayout , i have a button at the end of the layout , the entire layout is visible and scrollable but the button at the end is not visible , it becomes visible if i put it at first or make space for the button without the scroll view.
code
<?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">
<LinearLayout
android:id="#+id/container1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20sp"
android:orientation="horizontal"
android:padding="25sp"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="25sp"
android:layout_weight="1"
android:fontFamily="#font/roboto_bold"
android:text="TEST"
android:textSize="20sp" />
<ImageView
android:id="#+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="25sp"
android:contentDescription="close"
android:src="#drawable/test" />
</LinearLayout>
<ScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/container1">
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="25sp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="TEXT"
android:importantForAutofill="no"
android:inputType="text"
android:padding="40sp"
android:textSize="22sp"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="TEXT"
android:importantForAutofill="no"
android:inputType="text"
android:padding="40sp"
android:textSize="22sp"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="TEXT"
android:importantForAutofill="no"
android:inputType="text"
android:padding="40sp"
android:textSize="22sp"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="TEXT"
android:importantForAutofill="no"
android:inputType="text"
android:padding="40sp"
android:textSize="22sp"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="TEXT"
android:importantForAutofill="no"
android:inputType="text"
android:padding="40sp"
android:textSize="22sp"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="TEXT"
android:importantForAutofill="no"
android:inputType="text"
android:padding="40sp"
android:textSize="22sp"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="TEXT"
android:importantForAutofill="no"
android:inputType="text"
android:padding="40sp"
android:textSize="22sp"
android:textStyle="bold" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/blue"
android:text="#string/submit"
android:textColor="#color/white" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
I have tried changing to androidx.appcompat.widget.AppCompatButton , use image button but still no avail,
I tried to give hard coded height and width still it's not visible.
After some playing around i just found out that my last child is not visible be it button, text or any other
Any help is appreciated
You just have to add this line of code inside your Button Widget.
android:layout_marginBottom="50dp"
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/blue"
android:text="#string/submit"
android:textColor="#color/white"
android:layout_marginBottom="50dp" // Add this line
/>
This will solve your problem. Thank you.
You just need to change Scrollview code with
<ScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/container1">
Related
So I'm trying to set the edit text inside dialog to multi-lined but it doesn't do so it only appears in single-line for some reason
and it just keeps going to the right instead of going down(\n).
I set the edit text to multiline and the single line to be false but nothing works
here is the XML code for the dialog:
<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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/item_background_gray"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0"
android:padding="8dp"
app:srcCompat="#drawable/ic_baseline_radio_button_unchecked_24"
app:tint="#66FFFFFF" />
<EditText
android:id="#+id/et_missionText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="2"
android:background="#null"
android:ems="10"
android:gravity="top|left"
android:hint="Add mission"
android:importantForAutofill="no"
android:inputType="textImeMultiLine"
android:lines="8"
android:minHeight="48dp"
android:overScrollMode="always"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:scrollbars="vertical"
android:scrollHorizontally="false"
android:singleLine="false"
android:textColor="#color/white"
android:textColorHint="#B0FFFFFF" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab_addMission"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:backgroundTint="#color/item_background_gray"
android:clickable="true"
android:contentDescription="#string/app_name"
android:focusable="true"
app:borderWidth="0dp"
app:fabCustomSize="40dp"
app:srcCompat="#drawable/ic_round_arrow_circle_up_24"
app:tint="#color/add_button_background_gray" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Thank you for your help.
I have checked your code and fixed the issue. You only need to remove below line from your code:
android:inputType="textImeMultiLine"
I am also posting edited code below:
<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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/item_background_gray"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0"
android:padding="8dp"
app:srcCompat="#drawable/ic_baseline_radio_button_unchecked_24"
app:tint="#66FFFFFF" />
<EditText
android:id="#+id/et_missionText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="2"
android:background="#null"
android:ems="10"
android:gravity="top|left"
android:hint="Add mission"
android:importantForAutofill="no"
android:lines="8"
android:minHeight="48dp"
android:overScrollMode="always"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:scrollbars="vertical"
android:scrollHorizontally="false"
android:singleLine="false"
android:textColor="#color/white"
android:textColorHint="#B0FFFFFF" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab_addMission"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:backgroundTint="#color/item_background_gray"
android:clickable="true"
android:contentDescription="#string/app_name"
android:focusable="true"
app:borderWidth="0dp"
app:fabCustomSize="40dp"
app:srcCompat="#drawable/ic_round_arrow_circle_up_24"
app:tint="#color/add_button_background_gray" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I have the Button at the end of TextView:
When text is increasing, I get the following:
But I want that my button locates only at the end of text and doesn't move out of the screen when text is large:
This is my 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:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:maxLines="1"
android:text="Long text without button"
android:textColor="#000"
android:textSize="36sp" />
<FrameLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" >
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="Button" />
</FrameLayout>
</LinearLayout>
If I move layout_weight from FrameLayout to AppCompatTextView then I get needed result, but with smal text I get the following:
I tried with LinearLayout weights and ConstraintLayout, but nothing to help me.
How to achieve this?
You just use ConstraintLayout.
Try this
<?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">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/text"
android:layout_width="0dp" <-- It means using match-constraint.
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:maxLines="1"
android:text="Long text without button"
android:textColor="#000"
android:textSize="36sp"
app:layout_constraintEnd_toStartOf="#+id/button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="Button"
app:layout_constraintBottom_toBottomOf="#id/text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/text"
app:layout_constraintTop_toTopOf="#id/text" />
</androidx.constraintlayout.widget.ConstraintLayout>
Result
Additional XML - version wrap_content
<?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">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:maxLines="1"
android:text="short text"
android:textColor="#000"
android:textSize="36sp"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toStartOf="#+id/button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="Button"
app:layout_constraintBottom_toBottomOf="#id/text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/text"
app:layout_constraintTop_toTopOf="#id/text" />
</androidx.constraintlayout.widget.ConstraintLayout>
Modify layout_constraintHorizontal_bias attributes of TextView to fit layout you want.
Try this method using Grid Layout and AppcompatTextview hope it helps you.
<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:padding="10dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:rowCount="1">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/text"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeStepGranularity="2sp"
android:maxLines="1"
android:layout_columnWeight="0"
android:text="Long text without button"
android:textColor="#000"
android:textSize="20sp" />
<FrameLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="Button" />
</FrameLayout>
</GridLayout>
</LinearLayout>
I have a ConstraintLayout inside a ScrollView which is the root view of my layout. I wanted the ScrollView to kick in scrolling as soon as the height of the device is less than that is required for the layout.
My layout xml is:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
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"
tools:context="com.clickagee.babybind.AccountSettingActivity"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:fillViewport="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_account_title"
style="#style/textXLargePurple"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_padding_size_medium"
android:layout_marginTop="#dimen/margin_padding_size_medium"
android:text="#string/account"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/btn_add_partner"
style="#style/button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginEnd="#dimen/margin_padding_size_medium"
android:background="#drawable/custom_button_purple_outline"
android:paddingEnd="#dimen/margin_padding_size_medium"
android:paddingStart="#dimen/margin_padding_size_medium"
android:text="#string/add_partner"
android:textColor="#color/colorAccent"
app:layout_constraintBottom_toBottomOf="#id/tv_account_title"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#id/tv_account_title" />
<LinearLayout
android:id="#+id/ll_upload_change_photo_pane"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_padding_size_large"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/btn_add_partner">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/civ_change_upload_photo"
android:layout_width="130dp"
android:layout_height="130dp"
android:src="#drawable/ic_upload_user_image" />
<TextView
android:id="#+id/tv_upload_change_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/upload_photo" />
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/til_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_padding_size_medium"
android:layout_marginStart="#dimen/margin_padding_size_medium"
android:layout_marginTop="#dimen/margin_padding_size_medium"
app:layout_constraintTop_toBottomOf="#id/ll_upload_change_photo_pane">
<android.support.design.widget.TextInputEditText
android:id="#+id/et_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/name_hint"
android:inputType="textCapWords"
android:lines="1"
android:maxLines="1"
android:singleLine="true"
android:paddingBottom="#dimen/margin_padding_size_medium"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:id="#+id/tv_gender_account_setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_padding_size_medium"
android:layout_marginTop="#dimen/margin_padding_size_small"
android:text="#string/gender"
android:textColor="#color/light_grey"
android:textSize="#dimen/text_size_small"
app:layout_constraintTop_toBottomOf="#id/til_user_name" />
<RadioGroup
android:id="#+id/rg_user_gender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_padding_size_medium"
android:layout_marginStart="#dimen/margin_padding_size_medium"
android:layout_marginTop="#dimen/margin_padding_size_small"
android:orientation="horizontal"
android:weightSum="3"
app:layout_constraintTop_toBottomOf="#id/tv_gender_account_setting">
<RadioButton
android:id="#+id/rb_user_male_account_settings"
style="#style/textLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_padding_size_medium"
android:layout_weight="1"
android:background="#drawable/rbtn_selector"
android:button="#drawable/custom_radio_button_male"
android:padding="#dimen/margin_padding_size_small"
android:paddingEnd="#dimen/margin_padding_size_medium"
android:text="#string/male"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#color/radio_button_text_colors" />
<RadioButton
android:id="#+id/rb_user_female_account_settings"
style="#style/textLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_padding_size_medium"
android:layout_weight="1"
android:background="#drawable/rbtn_selector"
android:button="#drawable/custom_radio_button_female"
android:padding="#dimen/margin_padding_size_small"
android:paddingEnd="#dimen/margin_padding_size_medium"
android:text="#string/female"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#color/radio_button_text_colors" />
<RadioButton
android:id="#+id/rb_user_other_account_settings"
style="#style/textLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/rbtn_selector"
android:button="#drawable/custom_radio_button_other"
android:padding="#dimen/margin_padding_size_small"
android:paddingEnd="#dimen/margin_padding_size_medium"
android:text="#string/other"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#color/radio_button_text_colors" />
</RadioGroup>
<android.support.design.widget.TextInputLayout
android:id="#+id/til_user_phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_padding_size_medium"
app:layout_constraintTop_toBottomOf="#id/rg_user_gender">
<android.support.design.widget.TextInputEditText
android:id="#+id/et_user_phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_padding_size_medium"
android:layout_marginStart="#dimen/margin_padding_size_medium"
android:hint="#string/phone_number_hint"
android:inputType="phone"
android:lines="1"
android:maxLines="1"
android:singleLine="true"
android:paddingBottom="#dimen/margin_padding_size_medium"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/til_user_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_padding_size_medium"
android:layout_marginStart="#dimen/margin_padding_size_medium"
android:layout_marginTop="#dimen/margin_padding_size_medium"
app:layout_constraintTop_toBottomOf="#id/til_user_phone_number">
<android.support.design.widget.TextInputEditText
android:id="#+id/et_user_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/email_hint"
android:inputType="textEmailAddress"
android:lines="1"
android:maxLines="1"
android:singleLine="true"
android:paddingBottom="#dimen/margin_padding_size_medium"/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:id="#+id/btn_save_details_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="#dimen/margin_padding_size_medium"
android:layout_marginStart="#dimen/margin_padding_size_medium"
android:layout_marginTop="#dimen/margin_padding_size_large"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#id/til_user_email">
<br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
android:id="#+id/btn_save_details"
style="#style/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/custom_button"
android:padding="#dimen/margin_padding_size_small"
android:text="#string/save_details"
android:textColor="#color/white"
app:spinning_bar_color="#color/white"
app:spinning_bar_padding="#dimen/spinning_bar_padding"
app:spinning_bar_width="#dimen/spinning_bar_width" />
</LinearLayout>
<Button
android:id="#+id/btn_cancel_account_settings"
style="#style/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_padding_size_medium"
android:layout_marginStart="#dimen/margin_padding_size_medium"
android:layout_marginTop="16dp"
android:background="#drawable/custom_button_purple_outline"
android:padding="#dimen/margin_padding_size_small"
android:text="#string/cancel"
android:textColor="#color/colorAccent"
app:layout_constraintTop_toBottomOf="#id/btn_save_details_ll"
android:layout_marginBottom="#dimen/margin_padding_size_small"/>
</android.support.constraint.ConstraintLayout>
</ScrollView>
But instead I am getting scroll whether the required height is less or not.
A screenshot of this unusual behavior is
The following should not have happened, Am I missing anything here?:
You're missing a layout_constraintBottom_toBottomOf="parent" to your btn_cancel_account_settings
<Button
android:id="#+id/btn_cancel_account_settings"
style="#style/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_padding_size_medium"
android:layout_marginStart="#dimen/margin_padding_size_medium"
android:layout_marginTop="16dp"
android:background="#drawable/custom_button_purple_outline"
android:padding="#dimen/margin_padding_size_small"
android:text="#string/cancel"
android:textColor="#color/colorAccent"
app:layout_constraintTop_toBottomOf="#id/btn_save_details_ll"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="#dimen/margin_padding_size_small"/>
Change
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
Its because your text input field has default focus. Give up the focus from input text field and add the following property: app:layout_constraintBottom_toBottomOf="parent" to btn_cancel_account_settings.
I am trying to emulate an iOS-like keyboard for my Android app. Simply put, the contents of my activity should scroll behind the keyboard without resizing the spacing (which is what android:windowSoftInputMode="stateHidden|adjustResize" does).
I can achieve a close scroll behavior by making my parent layout a ScrollView (as suggested in Make soft keyboard behave like IOS in Android), but doing so also scrolls my custom action bar (which is an included android.support.v7.widget.Toolbar). Either I am not implementing a custom action bar correctly (so it is always at the top of the screen, ignoring scrolling), or there is some trick to get the soft keyboard to only scroll a resize (and scroll) a specific element to make room for itself.
Hopefully this simple picture illustrates what I'm trying to achieve. In the screen on the right, the actionbar is left untouched and the main content spacin remains the same and the view is scrollable.
This is my custom actionbar layout that I include in my activity.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/actionbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#color/primaryRed"
android:elevation="4dp"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="center_vertical"
android:layout_marginStart="-7dp"
android:contentDescription="#string/back"
android:scaleType="centerInside"
android:src="#drawable/ic_up_unpadded" />
<TextView
android:id="#+id/hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="20dp"
android:text="#string/back"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/theGlassFiles"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="22sp" />
</android.support.v7.widget.Toolbar>
The current view experiment layout is below. I've tried many things, none of which work. The one below is my latest test, which also does not achieve what I am try to get to.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:fitsSystemWindows="true"
tools:context="JoinActivity">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<include
layout="#layout/actionbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/message"
android:layout_width="362dp"
android:layout_height="wrap_content"
android:layout_marginTop="76dp"
android:gravity="center"
android:lineSpacingExtra="8sp"
android:text="#string/joinMessage"
android:textColor="#color/primaryBlue"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.489"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/form"
android:layout_width="362dp"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingTop="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.489"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/message"
app:layout_constraintVertical_bias="0.176">
<EditText
android:id="#+id/firstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/firstNameHint"
android:imeOptions="actionDone"
android:inputType="textPersonName" />
<EditText
android:id="#+id/middleName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/middleNameHint"
android:imeOptions="actionDone"
android:inputType="textPersonName" />
<EditText
android:id="#+id/lastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/lastNameHint"
android:imeOptions="actionDone"
android:inputType="textPersonName" />
<EditText
android:id="#+id/town"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/townHint"
android:imeOptions="actionDone"
android:inputType="textPersonName" />
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/passwordHint"
android:imeOptions="actionDone"
android:inputType="textPersonName" />
<EditText
android:id="#+id/confirmPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/confirmPasswordHint"
android:imeOptions="actionDone"
android:inputType="textPersonName" />
<Button
android:id="#+id/joinButton"
android:layout_width="match_parent"
android:layout_height="49dp"
android:layout_marginTop="25dp"
android:background="#color/primaryRed"
android:text="#string/join"
android:textAllCaps="false"
android:textColor="#android:color/white"
android:textSize="22sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
EDIT
Swapping around the parent/children layouts, I achieve something really close to what I'm aiming for. The actionbar always is on top, and the keyboard only resizes the scroll view. However, when I scroll I cannot scroll above the first EditText element. Using the picture, I can only scroll up to the first input, and cannot continue to scroll up and see the green icon. Using my actual XML layout, I cannot scroll to see the TextView component. Here is the updated 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="JoinActivity">
<include
layout="#layout/actionbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_below="#id/actionbar">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView
android:id="#+id/message"
android:layout_width="362dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:gravity="center"
android:lineSpacingExtra="8sp"
android:text="#string/joinMessage"
android:textColor="#color/primaryBlue"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.489"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/form"
android:layout_width="362dp"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingTop="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.489"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/message"
app:layout_constraintVertical_bias="0.464">
<EditText
android:id="#+id/firstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/firstNameHint"
android:imeOptions="actionDone"
android:inputType="textPersonName" />
<EditText
android:id="#+id/middleName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/middleNameHint"
android:imeOptions="actionDone"
android:inputType="textPersonName" />
<EditText
android:id="#+id/lastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/lastNameHint"
android:inputType="textPersonName" />
<EditText
android:id="#+id/town"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/townHint"
android:inputType="textPersonName" />
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/passwordHint"
android:inputType="textPersonName" />
<EditText
android:id="#+id/confirmPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/confirmPasswordHint"
android:inputType="textPersonName" />
<Button
android:id="#+id/joinButton"
android:layout_width="match_parent"
android:layout_height="49dp"
android:layout_marginTop="25dp"
android:background="#color/primaryRed"
android:text="#string/join"
android:textAllCaps="false"
android:textColor="#android:color/white"
android:textSize="22sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
</RelativeLayout>
In my App I'm using a Custum Dialog (android.app.Dialog) with three Edit Texts in it. I'm able to set the next focus from the first to the second EditText when I press the next Button on the SoftKeyboard, but it doesen't work to set the focus on the third EditText. I already tried to set nextFocusForward or nextFocusDown and so on but it still doesn't work.
Here is the XML Layout from my Custom Dialog:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/addcard_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/dialog_addcard_info" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/addcard_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:hint="#string/name"
android:inputType="text"
android:lines="1"
android:maxLines="1"
android:scrollHorizontally="true" />
<EditText
android:id="#+id/addcard_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:hint="#string/number"
android:inputType="number"
android:maxLength="16"
android:scrollHorizontally="true"/>
<EditText
android:id="#+id/addcard_pin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:hint="#string/pin"
android:inputType="numberPassword"
android:maxLength="4"
android:textSize="14sp"
android:scrollHorizontally="true"/>
</LinearLayout>
<TextView
android:id="#+id/addcard_errormessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="#string/error"
android:textColor="#ff0000"
android:textStyle="bold"
android:visibility="gone" />
<Button
android:id="#+id/addcard_verify"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="#string/verify" />
</LinearLayout>
Does anyone have an idea why i'm not able to set the focus on the third EditText?
Thanks in advance.
try this one in your code :)
<EditText
android:id="#+id/addcard_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:hint="#string/number"
android:inputType="number"
android:maxLength="16"
android:imeOptions="actionNext" // try this one
android:nextFocusDown="#+id/addcard_errormessage" // and add this one
android:scrollHorizontally="true"/>