Put ImageButton between two view groups - android

I have a LinearLayout with a Toolbar inside it and an EditText and a Button. I'm using images to express what i want, it is simple:
This is what I have right now: (the ImageButton with the logo is in the Toolbar)
And this is what I want to achieve: (The ImageButton with the logo is between the Toolbar and the LinearLayout)
This is my XML code for the layout file:
<?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:fab="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/secondColor"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/mainColor"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:paddingLeft="-10dp">
<ImageButton
android:id="#+id/btnMenu"
style="#android:style/Widget.DeviceDefault.ImageButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/menu_principal" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:layout_weight="5"
android:fontFamily="#font/roboto_medium"
android:text="#string/app_name"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="24sp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="false"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:background="#null"
android:scaleType="fitXY"
android:src="#drawable/spotify_logo" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="#string/editReminderTitleHint"
/>
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>

You can achieve this by changing your LinearLayout top-level view into a ConstraintLayout:
<?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.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<EditText
android:id="#+id/edit"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:hint="Reminder title"/>
<Button
android:id="#+id/button"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#+id/edit"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="BUTTON"/>
<ImageButton
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="#+id/toolbar"
app:layout_constraintEnd_toEndOf="parent"/>
</android.support.constraint.ConstraintLayout>
The important part here is that you constrain both the top and bottom of the ImageButton to the bottom of the Toolbar. This will center it on the bottom edge of the toolbar.
Note that I didn't set a special background for my example ImageButton, but you can make it a circle and it will work just fine.

Related

ImageView does not adopt to the size of the Relativelayout -> wrap_content

I am trying to get a layout like this:
my layout
the red colour beckground is just for better visualisation.
and i want that if the text in the edittext exeeds the given space of the edittext, that it expands only below and wraps the text. The Relativelayout and the constraintlayout including the edittext do the behavior i need but the imageview for the background won't expand to the now larger content of edittext.
problem
I tried 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/red">
<RelativeLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:minHeight="60dp"
android:maxHeight="300dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/layout2"
android:layout_width="315dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<EditText
android:id="#+id/editText"
android:layout_width="315dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:fontFamily="sans-serif-medium"
android:maxHeight="290dp"
android:text="#string/test"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="18dp"
app:layout_constrainedHeight="true"
app:layout_constraintStart_toStartOf="#+id/layout2"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageView
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.4"
android:background="#drawable/add_skill_design"
android:maxHeight="300dp"
android:minHeight="60dp" />
<ImageView
android:id="#+id/add_skill_upload_circle"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/circle_skill"
android:layout_marginTop="20dp"
android:layout_marginStart="10dp" />
<ImageView
android:id="#+id/add_skill_upload_remove"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/remove"
android:layout_marginTop="15dp"
android:layout_marginEnd="10dp"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
What am i doing wrong? I need this for a project.
You can set the vertical alignment of the ImageView with the background drawable to depend on the boundaries of the ConstraintLayout:
<ImageView
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.4"
android:background="#drawable/add_skill_design"
android:maxHeight="300dp"
android:minHeight="60dp"
android:layout_alignTop="#+id/layout2"
android:layout_alignBottom="#+id/layout2" />

How to fix some views in Relative Layout

I have implemented simple relative layout for chat inside one of fragments layout called "Chat". The problem is that when I click EditText to type message, Linear Layout for sending messages disappears and messages are superimposed on the items above(I want them no to overlay any element except recycler view).
How to fix it?
Below I put the code of layout and screenshots Layout and Layout after click
<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=".ChatFragment">
<Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:theme="#style/ThemeOverlay.AppCompat.Light"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/start_at_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Start at"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</Toolbar>
<LinearLayout
android:id="#+id/chat_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/white"
android:gravity="center_horizontal"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent">
<ImageButton
android:id="#+id/attachBtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#null"
android:src="#drawable/ic_attach_file"
tools:ignore="SpeakableTextPresentCheck" />
<EditText
android:id="#+id/messageEt"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#null"
android:hint="Start typing..."
android:inputType="textCapSentences|textMultiLine" />
<ImageButton
android:id="#+id/send_btn"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#null"
android:src="#drawable/ic_send"
tools:ignore="SpeakableTextPresentCheck" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/chat_layout"
android:layout_below="#+id/toolbar"
android:background="#AEFFFFFF"
tools:listitem="#layout/message_left" />
</RelativeLayout>

Constraint layout with wrap_content clips it's content

Recently I've bumped into a strange ConstraintLayout behavior. What I tried to do was a simple layout with ImageView, Button and a TextView. Here's the code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="#null"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingBottom="10dp"
android:paddingEnd="20dp"
android:paddingStart="20dp"
android:text="TEST TEXT"
android:paddingTop="20dp"
app:layout_constraintStart_toStartOf="#id/image"
app:layout_constraintTop_toBottomOf="#+id/button" />
<android.support.v4.widget.Space
android:id="#+id/marginSpacer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="10dp"
app:layout_constraintBottom_toBottomOf="#id/image" />
<Button
android:id="#id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:background="#drawable/button_bg"
android:text="BUTTON"
app:layout_constraintTop_toBottomOf="#id/marginSpacer" />
</android.support.constraint.ConstraintLayout>
The ImageView content is loaded using Glide like this:
Glide.with(this).load("https://homepages.cae.wisc.edu/~ece533/images/monarch.png").into(imageView);
Here is how I wanted it to look like:
And here's what I actually got:
My intent was to make the text align relative to the button, not the image, how do I make this happen? Why did the ConstraintLayout clip itself to the ImageView? On the other hand, if I align the text relative to the image everything works great and nothing is clipped.
The full source is available here:
https://github.com/satorikomeiji/ConstraintLayoutBug
Use this for your Button:
#+id/button
instead of
android:id="#id/button"
You'll be able to design urself.
I would suggest you to add loading image:
.placeholder(R.drawable.ic_error_black_48px)
My Layout:
<?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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="81dp">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="#null" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:paddingBottom="10dp"
android:paddingEnd="20dp"
android:paddingStart="20dp"
android:paddingTop="20dp"
android:text="TEST TEXT"
app:layout_constraintStart_toStartOf="#+id/ButtonLayout"
app:layout_constraintTop_toBottomOf="#+id/ButtonLayout" />
<android.support.constraint.ConstraintLayout
android:id="#+id/ButtonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="#+id/image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/image">
<View
android:id="#+id/dummyView"
android:layout_width="match_parent"
android:layout_height="15dp" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:background="#drawable/button_bg"
android:text="BUTTON"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/dummyView" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
Preview:
You need to align something to the bottom of the parent
Align TEST TEXT TextView bottom to the bottom of parent like this:
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingBottom="10dp"
android:paddingEnd="20dp"
android:paddingStart="20dp"
android:text="TEST TEXT"
android:paddingTop="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#id/image"
app:layout_constraintTop_toBottomOf="#+id/button" />
And add plus sign in button id
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:background="#drawable/button_bg"
android:text="BUTTON"
app:layout_constraintTop_toBottomOf="#id/marginSpacer" />
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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="81dp">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher_background"
android:adjustViewBounds="true"
android:contentDescription="#null" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:paddingBottom="10dp"
android:paddingEnd="20dp"
android:paddingStart="20dp"
android:paddingTop="20dp"
android:text="TEST TEXT"
app:layout_constraintStart_toStartOf="#+id/ButtonLayout"
app:layout_constraintTop_toBottomOf="#+id/ButtonLayout" />
<android.support.constraint.ConstraintLayout
android:id="#+id/ButtonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="#+id/image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/image">
<View
android:id="#+id/dummyView"
android:layout_width="match_parent"
android:layout_height="15dp" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:text="BUTTON"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/dummyView" />
</android.support.constraint.ConstraintLayout>

How to tie a BottomSheet at the bottom view of the layout

Through ConstraintLayout, I am using a BottomSheet to show content of a map detail. My idea is the same used in GoogleMaps, but without the image carousel at the top.
I need to find some property to tie the BottomSheet in the bottom, using only the size from its layout, not the whole window, as below:
Here is my XML from parent view:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mapbox.mapboxsdk.maps.MapView
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
mapbox:center_latitude="0"
mapbox:center_longitude="0"
mapbox:style_url="#string/style_mapbox_streets"
mapbox:zoom="12" />
<!--
<ImageView
android:id="#+id/bottom_sheet_backdrop"
android:layout_width="match_parent"
android:layout_height="#dimen/anchor_point"
android:fitsSystemWindows="true"
app:layout_behavior="#string/BackDropBottomSheetBehavior" />
-->
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
app:anchorPoint="#dimen/anchor_point"
app:behavior_hideable="true"
app:behavior_peekHeight="#dimen/bottom_sheet_peek_height"
app:layout_behavior="#string/BottomSheetBehaviorGoogleMapsLike">
<include
layout="#layout/places_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" />
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/places_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
android:clickable="true"
android:src="#drawable/ic_directions"
app:elevation="3dp"
app:layout_anchor="#id/bottom_sheet"
app:layout_anchorGravity="top|right|end"
app:layout_behavior="#string/ScrollAwareFABBehavior" />
</android.support.design.widget.CoordinatorLayout>
Here is the design from BottomSheet "layout/places_bottom_sheet"
<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:background="#android:color/white"
android:orientation="vertical"
android:paddingBottom="16dp">
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/bottom_sheet_place_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="8dp"
android:src="#drawable/watchmen" />
<TextView
android:id="#+id/bottom_sheet_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="16dp"
android:text="Bottom Sheet Title"
android:textSize="20sp" />
</LinearLayout>
<!-- line separator -->
<include
android:id="#+id/include2"
layout="#layout/line_separator"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="0dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout2" />
<!-- street address-->
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="0dp"
android:orientation="horizontal"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/include2">
<ImageView
android:id="#+id/bottom_sheet_address_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:scaleType="center"
android:src="#drawable/ic_location_on_black_24dp" />
<TextView
android:id="#+id/bottom_sheet_address_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="16dp"
android:text="Rua tal, NÂș 1234"
android:textSize="14sp" />
</LinearLayout>
<!-- phone -->
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout">
<ImageView
android:id="#+id/bottom_sheet_phone_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:scaleType="center"
android:src="#drawable/ic_phone_black_24dp" />
<TextView
android:id="#+id/bottom_sheet_phone_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="16dp"
android:text="(62) 983 234 544"
android:textSize="14sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
BottomSheet works only inside Coordinator Layout or as BottomSheetDialogFragment popup.
Because: app:layout_behavior is part of Coordinator Layout
It seems like at the moment there is no way of putting BottomSheet inside ConstraintsLayout, which would be awesome.
They both extend view group so maybe one day, we will see capabilities of Coordinator Layout inside ConstraintsLayout or some mix of two.
Set the gravity of the layout to bottom.
In places_bottom_sheet.xml, change the layout_height of the root ConstraintLayout to "match_parent".
Add this to bottom sheet. This will work like a charm!!!
android:layout_gravity="center_horizontal"

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