Android Studio: Layout incomprehensibly positioned - android

I've been trying out for a long time now but I just don't understand why "layout3" extends to the edge of the root element and not just to the right edge of "layout2" as I wanted it to.
Here is the XML 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginBottom="50dp"
android:id="#+id/layout1">
<TextView
android:layout_width="224dp"
android:layout_height="159dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="184dp"
app:layout_constraintVertical_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
android:id="#+id/textview1"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/textview1"
android:layout_marginTop="20dp"
app:layout_constraintStart_toStartOf="#id/layout1"
app:layout_constraintEnd_toEndOf="#id/layout1"
android:layout_marginEnd="500dp"
android:id="#+id/layout2">
<TextView
android:layout_width="224dp"
android:layout_height="159dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_marginStart="20dp"
android:id="#+id/textview2"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="100dp"
app:layout_constraintTop_toBottomOf="#+id/textview1"
android:layout_marginTop="20dp"
app:layout_constraintStart_toEndOf="#id/layout2"
app:layout_constraintEnd_toEndOf="#id/layout1"
android:id="#+id/layout3">
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Here is a picture from the editor:

In layout3, instead of
android:layout_width="match_parent"
write:
android:layout_width="0dp"
and it will be placed right next to the top of layout2.
In case you wonder how it has a wide range even with width=0dp, it is because of these 2 constraints:
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/layout2"
They pull LinearLayout to 2 opposite sides, and as a result it unwraps.

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>

Why does a white border in a card view appears when load an image?

I created a component for my app which I use like a card. It has some textviews and an end image, but the image always appears with some withe border liek in the image bellow:
I tried everything to fix it but I can figure out how and it's important because the component it's used in almost all the app and in all of them the all the images appear with some withe border.
Component code:
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="106dp"
app:cardCornerRadius="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:orientation="vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/image_card_end"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/txt_card_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp"
app:textType="semibold"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/second_description_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:id="#+id/txt_card_second_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:textSize="14dp"
app:textType="regular"
/>
</LinearLayout>
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/image_card_end"
android:layout_width="98dp"
android:layout_height="106dp"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="#drawable/card_appointment_image" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
And this is how I use it:
<com.univer.components.card.BasicCard
android:id="#+id/home_card_auto_evaluation_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:cardCornerRadius="8dp"
app:cardDescription="#string/home_card_selfdiagnosis_description"
app:cardEndImage="#string/image_home_card_symptomchecker"
app:cardHeader="#string/home_card_selfdiagnosis_header" />
Set a background which is easily visible(eg: red) to your cardview and run the app.
If the red section gets visible it means the inner constraint layout isn't wrapping the cardview completely . If that is the case I would suggest experimenting with scale type as so
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/image_card_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center-crop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="#drawable/card_appointment_image" />

Android: ScrollView containing two nested ConstraintLayouts, cant fill screen horizontally

I am having an issue with the following XML:
<?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=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp">
<View
android:id="#+id/block"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#419E9E9E"
android:orientation="horizontal"
android:paddingTop="8dp"
android:paddingBottom="8dp"
app:layout_constraintTop_toBottomOf="#id/block"></LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/holder"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout">
<TextView
android:id="#+id/holderText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="12sp"
android:gravity="center_vertical"
android:maxLines="4"
android:text="Hello World"
android:textColor="#color/colorPrimaryDark"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/holder" />
<Button
android:id="#+id/Button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
Vertically, the layout does what I want: it puts the last layout and fills the screen.
However, when the device is flipped horizontally, the bottom portion (the nested constraintlayout) disappears due to the constraint on itself of app:layout_constraintBottom_toBottomOf="parent"
"How do I fill the screen with a second layout while still having it scroll horizontally ?"
I have attached pics and a demo repository to isolate the problem.
Link: https://github.com/taesookim0412/StackOverflow_Question_Android_NestedConstraintLayouts_ScrollView
I've found a solution. Instead of minHeight, you can use
app:layout_constraintHeight_min="100dp"

How do I make two textviews in a ConstraintLayout in a CardView be flush?

I'm a bit new to Android development, so I apologize if this question is simple. I have two textviews stacked vertically that I would like to get flush with each other. There's too much whitespace between the two elements:
I have the following activity layout in which I've tried to make the TextViews flush by using a constraint view and setting the margin between the bottom and top to 0dp:
<?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:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".PackageService">
<android.support.v7.widget.CardView
android:id="#+id/card_inventory"
android:layout_width="match_parent"
android:layout_height="101dp"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_inventory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:src="#android:drawable/btn_star"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.048"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.49" />
<TextView
android:id="#+id/text_inventory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginStart="32dp"
android:text="Button Title"
android:textAppearance="#android:style/TextAppearance.Material.Large"
app:layout_constraintBottom_toTopOf="#id/text_last_scan"
app:layout_constraintStart_toEndOf="#+id/image_inventory"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/text_last_scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button Subtitle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/text_inventory"
app:layout_constraintTop_toBottomOf="#+id/text_inventory" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Any help would be appreciated.

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