windowSoftInput hides items in recycleview - android

Im creating a chat app and so far it looks something like this:
The moment I start typing it hides the last 2 items and looks like (the edittext hides g,h messages):
My XML file looks as follows:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ChatActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_Messages"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/ib_Send"
style="?android:borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:adjustViewBounds="true"
android:src="#drawable/ic_location_on_black_24dp"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<EditText
android:id="#+id/et_Message"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:hint="enter message here"
android:backgroundTint="#color/colorLightPurple"
android:inputType="textMultiLine|textPersonName"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/ib_Send"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
and I have added to my manifest android:windowSoftInputMode="adjustPan"
Is there a way that I can make sure that my recycleview will always show the lates messages/ make sure the edittext wont hide?
Thank you

Use the combination of relative and linear layout and then use marginBottom inside recyclerview. Hope you will find it.
<?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=".ChatActivity">
<include
android:id="#+id/chat_toolbar"
layout="#layout/app_bar_layout">
</include>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/private_messages_list_of_users"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/chat_toolbar"
android:layout_above="#+id/chat_linear_layout"
android:layout_marginBottom="6dp"
>
</androidx.recyclerview.widget.RecyclerView>
<RelativeLayout
android:id="#+id/chat_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:background="#android:color/background_light"
android:orientation="horizontal"
>
<ImageButton
android:id="#+id/send_files_btn"
android:layout_width="60dp"
android:layout_height="50dp"
android:src="#drawable/ic_attach_file_black_24dp"
android:layout_alignParentStart="true"
android:backgroundTint="#android:color/white"
/>
<EditText
android:id="#+id/input_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="type message here..."
android:padding="15dp"
android:maxLines="5"
android:layout_toEndOf="#+id/send_files_btn"
android:layout_toStartOf="#+id/send_message_btn"
/>
<ImageButton
android:id="#+id/send_message_btn"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:src="#drawable/send_message"
android:layout_alignParentEnd="true"
android:backgroundTint="#android:color/white"
/>
</RelativeLayout>
</RelativeLayout>
check out my above example...

Related

How to add recylerview in 1/3rd part of activity

I have on activity in which i need to add one horizontal list for showing the formats of image which should be appear in the lower part of the activity. Here is my xml file.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:fitsSystemWindows="true"
tools:context=".view.quickaction.QuickActionVideoActivity">
<RelativeLayout
android:id="#+id/quick_action_video_header_contatiner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/quick_action_video_close"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginTop="20dp"
android:text="#string/button_cancel"
android:textColor="#color/express_purple"
android:textSize="18dp" />
<TextView
android:id="#+id/quick_action_video_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/quick_action_video_close"
android:layout_marginTop="30dp"
android:fontFamily="#font/adobe_clean_bold"
android:text="#string/quick_action_resize_video_header"
android:textColor="#color/black_alpha_85"
android:textSize="32dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/quick_action_video_title"
android:text="#string/powered_by_magicX"
android:textColor="#color/black_alpha_85"
android:textSize="14dp" />
</RelativeLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/zoom_surface"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="15dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="15dp"
android:background="#drawable/rounded_rectangle_rect"
android:visibility="visible"
app:layout_constraintDimensionRatio="H,5:4"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/quick_action_video_header_contatiner">
<com.otaliastudios.zoom.ZoomSurfaceView
android:id="#+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
app:horizontalPanEnabled="true"
app:verticalPanEnabled="true"
app:zoomEnabled="true" />
</androidx.constraintlayout.widget.ConstraintLayout>
<RelativeLayout
android:id="#+id/relativeLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/zoom_surface"
app:layout_constraintBottom_toTopOf="#id/relativeLayout2"
tools:ignore="MissingConstraints">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal"
app:layout_constrainedHeight="true"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="#+id/quick_action_video_save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:layout_weight="1"
android:background="#drawable/button_bg_rounded_corners"
android:fontFamily="#font/adobe_clean_bold"
android:text="#string/save_share_option"
android:textColor="#color/white_alpha_80" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
It should look like this:
But this recyler-view while loading taking the whole space of the activity and one header also. Can you tell me what is wrong in this? Can recyler-view won't be able to host inside this view.
The issue is that you don't have a top to bottom of constraint and have set the height as match constraints.. However for layouts like this i have a few tips..
do the layouts first with constant heights like 200 dp or so and change them later
follow a top to bottom or a bottom to top approach that is one view at the top and everything else is done taking that as anchor
use constraint layouts throughout. You don't need any other layout type if you're using constraint layout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/zoom_surface"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="15dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="15dp"
android:background="#drawable/rounded_rectangle_rect"
android:visibility="visible"
app:layout_constraintDimensionRatio="H,5:4"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/quick_action_video_header_contatiner"
app:layout_constraintBottom_toTopOf=" ">add the suitable id
<com.otaliastudios.zoom.ZoomSurfaceView
android:id="#+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
app:horizontalPanEnabled="true"
app:verticalPanEnabled="true"
app:zoomEnabled="true" />
</androidx.constraintlayout.widget.ConstraintLayout>

Images are not aligning properly in the horizontal RecyclerView in Android Studio

and
As you can see, the images don't seem to be aligning with each other very well. It seems to happen when the text for "Hobby" grows longer than the ones next to it. I still can't seem to fix this though. Here's the xml for the horizontal view:
<FrameLayout
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.recyclerview.widget.RecyclerView
android:id="#+id/recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:scrollbars="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
/>
</FrameLayout>
and here's the xml for my adapter:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/dog_img"
android:layout_width="match_parent"
android:layout_height="194dp"
android:scaleType="centerCrop"
android:importantForAccessibility="no"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textAppearance="#style/TextAppearance.MaterialComponents.Headline6"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/dog_img"
/>
<TextView
android:id="#+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/name"
/>
<TextView
android:id="#+id/hobby"
android:layout_width="156dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/name"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
I really want the images to line up with each other regardless of the length of the "Hobby". Sorry if this might seem a bit basic, but I'm new to Android Studio. Anyways, thanks in advance!
I'll suggest you set the scale type to centre inside and another tag adjustViewBounds like the following code.
android:adjustViewBounds="true" and android:scaleType="centerInside"
<ImageView
android:id="#+id/dog_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:importantForAccessibility="no"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:adjustViewBounds="true"
android:scaleType="centerInside"
/>

Wrong app display on both physical and virtual device

I tried on both emulator and physical device ,with different layouts, but app shows only about sixty percent of layout,like its exceeding the visible screen and some component goes under.
I tried to use a scroll view,but no success.
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#242323"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<EditText
android:id="#+id/edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="blah blah"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="press"
android:layout_centerHorizontal="true"
android:layout_below="#id/edittext"
/>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
In your code,try to change this:
from
<RelativeLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
to
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
When using constraint layout you need to link your views to some other view/boundry. In your case your RelativeLayout was not linked to parent, and you were using an extra Layout so remove the Constraint layout and use just Relative layout.
That will work.
Try the following xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#242323"
tools:context=".MainActivity">
<EditText
android:id="#+id/edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="blah blah"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="press"
android:layout_centerHorizontal="true"
android:layout_below="#id/edittext"
/>
</RelativeLayout>
Remove the relative layout and just use constraint layout only. Note that your button and edittext have to be constrained to the parent view. Learn more about Constraint Layout at https://developer.android.com/reference/android/support/constraint/ConstraintLayout
Try the following xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#242323"
tools:context=".MainActivity">
<EditText
android:id="#+id/edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:hint="blah blah"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/edittext"
android:layout_centerHorizontal="true"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="press"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/edittext" />
</androidx.constraintlayout.widget.ConstraintLayout>

Spinner down arrow disappears below view background

The following views are inside a ConstraintLayout:
<View android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#color/white"
app:layout_constraintBottom_toBottomOf="#id/pickup_date"
app:layout_constraintTop_toTopOf="#id/pickup_date" />
<Spinner android:id="#+id/pickup_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
As you can see, it is hiding the down arrow on the spinner.
But when is set the visibility of the View to be gone it looks like this -
How do I achieve a white background using the view
Remove attribute app:layout_constraintTop_toTopOf="#id/pickup_date" from View.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp">
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Select a pickup date"
android:textColor="#000"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp" />
<Spinner
android:id="#+id/pickup_date"
android:layout_width="336dp"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3"
android:layout_marginTop="8dp"
tools:layout_editor_absoluteX="0dp" />
<View
android:layout_width="0dp"
android:layout_height="50dp"
android:background="#color/white"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/pickup_date"
tools:layout_editor_absoluteX="0dp" />
</android.support.constraint.ConstraintLayout>
OUTPUT:
UPDATE:
Your view constrain was not proper.
View attributes app:layout_constraintBottom_toBottomOf="#id/pickup_date" and app:layout_constraintTop_toTopOf="#id/pickup_date", will place View over center position of Spinner.
See documentation for details.
To show spinner over View, do below changes:
1. Add attribute app:layout_constraintTop_toBottomOf="#+id/textView3" to View.
2. Add attribute app:layout_constraintStart_toStartOf="#id/view" to spinner.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp">
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Select a pickup date"
android:textColor="#000"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp" />
<View
android:layout_width="wrap_content"
android:layout_height="70dp"
android:background="#color/white"
android:id="#+id/view"
tools:layout_editor_absoluteX="0dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<Spinner
android:id="#+id/pickup_date"
android:layout_width="352dp"
android:layout_height="30dp"
android:spinnerMode="dropdown"
app:layout_constraintStart_toStartOf="#id/view"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="33dp" />
</android.support.constraint.ConstraintLayout>
OUTPUT:
Hope this will help~

android scrollview not scrolling down after keyboard opens

I have a textview that is inside of a scrollview, it scrolls fine untill the soft keyboard is opened.
When the keyboard is opened it act like it scrolled up again with the height of the keyboard.
What I have tried
I tried this in the manifest, but yielded the exact same results
android:windowSoftInputMode="adjustResize"
Then this:
android:windowSoftInputMode="adjustPan"
That seemed to work, but the problem was that it was moving the whole screen up and taking the header out of view.
I also tried adding the following in the linear layout
android:focusable="true"
android:focusableInTouchMode="true"
That only caused the app not to focus on the input field (EditText) and the keyboard didn't open automatically, but when you clicked on the input field it would just act the same as before.
This is the XML file code:
<?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"
android:background="#color/lightGray"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_layout"
android:layout_marginTop="10dip" >
<LinearLayout
android:id="#+id/msg_list_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:color/background_light">
<Button
android:id="#+id/send_btn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="#string/txt_send" />
<EditText
android:id="#+id/msg_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/send_btn"
android:layout_toLeftOf="#+id/send_btn"
android:inputType="text" >
</EditText>
</RelativeLayout>
Any suggestions?
I had same problem and the solutions is this:
My activity was in fullscreen mode and scroll does not work in this mode this is a bug and we send a report to google.
Just look at your activity in manifest if there is a fullscreen mode just remove it.
I got this problem and it is a headache.
the soloution is instead of drawing an XML layout from the top of the screen, you need to draw it from the bottom of the screen.
look at these examples :
main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:fillViewport="true"
android:isScrollContainer="true"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<include layout="#layout/main_contents"/>
</ScrollView>
</android.support.constraint.ConstraintLayout>
main_contents.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp">
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.92" />
<android.support.v7.widget.CardView
android:id="#+id/card1"
android:layout_width="0dp"
android:layout_height="250dp"
android:layout_margin="30dp"
android:padding="10dp"
app:cardCornerRadius="10dp"
app:layout_constraintBottom_toTopOf="#+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/sam3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="sample"
android:textColor="#673AB7"
android:textSize="23sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/sam2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:backgroundTint="#673AB7"
android:digits="0123456789"
android:gravity="center"
android:hint="sample"
android:inputType="phone"
android:maxLength="11"
android:maxLines="1"
android:nextFocusDown="#id/sam1"
android:textColor="#673AB7"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sam3"
app:layout_constraintVertical_bias="0.3"/>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<Button
android:id="#+id/sam1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#fff"
android:background="#673AB7"
android:text="sample"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="#+id/card1"
app:layout_constraintEnd_toEndOf="#+id/card1"
app:layout_constraintStart_toStartOf="#+id/card1"
app:layout_constraintTop_toBottomOf="#+id/card1" />
</android.support.constraint.ConstraintLayout>
main_contents2.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp">
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.45" />
<android.support.v7.widget.CardView
android:id="#+id/card1"
android:layout_width="0dp"
android:layout_height="250dp"
android:layout_margin="30dp"
android:padding="10dp"
app:cardCornerRadius="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/sam2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:backgroundTint="#673AB7"
android:digits="0123456789"
android:gravity="center"
android:hint="sample"
android:inputType="phone"
android:maxLength="11"
android:maxLines="1"
android:nextFocusDown="#id/sam1"
android:textColor="#673AB7"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sam3"
app:layout_constraintVertical_bias="0.3" />
<TextView
android:id="#+id/sam3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="sample"
android:textColor="#673AB7"
android:textSize="23sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<Button
android:id="#+id/sam1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#fff"
android:background="#673AB7"
android:text="sample"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="#+id/card1"
app:layout_constraintEnd_toEndOf="#+id/card1"
app:layout_constraintStart_toStartOf="#+id/card1"
app:layout_constraintTop_toBottomOf="#+id/card1" />
</android.support.constraint.ConstraintLayout>
the second XML file main_contents2 drew from top and android just put the EditText from top of the keyboard.BUT the main_contents drawn from the bottom of the screen. so when the soft keyboard comes up the layout resizes.
Try changing the layout_height of scrollview to wrap_content.
All you need to do is
android:isScrollContainer="true"

Categories

Resources