To push Linear Layout with soft keyboard - android

Hi I've an xml layout in which I've two buttons at the bottom of the parent layout. Here whenever the soft keyboard opens those buttons are hidden, therefore I need to push the button above with the keyboard. I've posted my xml layout here, please refer to it and help me achieving this.
<?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="wrap_content"
android:isScrollContainer="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/view1"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/leftPane"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
<ListView
android:id="#+id/Left_listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0A2F41"
android:duplicateParentState="true"
android:fadingEdge="vertical"
android:gravity="center"
android:listSelector="#335E73"
android:scrollbars="none"
android:smoothScrollbar="true"
android:soundEffectsEnabled="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rightPane"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5">
<EditText
android:id="#+id/searchkeyword_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="#drawable/icon_close"
android:hint="Search"
android:inputType="textNoSuggestions"
android:maxLines="1"
android:paddingRight="10dp" />
<ListView
android:id="#+id/right_listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/searchkeyword_editText"
android:fadingEdge="vertical"
android:gravity="center"
android:scrollbars="none"
android:smoothScrollbar="true"
android:soundEffectsEnabled="true" />
</RelativeLayout>
</LinearLayout>
<View
android:id="#+id/view1"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_above="#+id/bottom_linearLayout"
android:background="#000"
android:visibility="visible" />
<LinearLayout
android:id="#+id/bottom_linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:visibility="visible">
<TextView
android:id="#+id/cancel_textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="12dp"
android:text="Cancel"
android:textSize="15sp" />
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="#000" />
<TextView
android:id="#+id/apply_textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#02B5CC"
android:gravity="center"
android:padding="12dp"
android:text="Apply"
android:textColor="#fff"
android:textSize="15sp"
android:visibility="visible" />
</LinearLayout>
</RelativeLayout>
Also in my Manifest I've added the below line in order to achieve the above action.
android:windowSoftInputMode="stateVisible|adjustResize"
I'd like to have something like this.

Try this:
android:windowSoftInputMode="adjustPan|adjustResize"

Related

Android XML cutting off bottom half of layout

I have a problem with my XML layout, something that I thought wouldn't give me many problems. I have a layout below in a scroll view, but the bottom of the layout is being cut off, I can't see anything past the second list view. From looking around, I can't seem to see anything wrong with the xml itself and I can't see what I am doing wrong.
I have tried the suggestion to the problem, that is adding a weight to each of the different elements but this still hasnt solved the problem.
I have also added the main activity in which the fragment is placed incase that might help solve the problem
Fragment XML
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/coordinatorLayout">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recipe Title"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:id="#+id/ingredientsHeading"
android:layout_below="#+id/text_input_layout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Ingredients"
android:textStyle="bold|italic"
android:layout_weight="1" />
<ListView
android:id="#+id/ingredientsList"
android:layout_below="#+id/ingredientsHeading"
android:layout_above="#+id/directionsHeading"
android:layout_width="wrap_content"
android:layout_height="195dp"
android:layout_weight="1"></ListView>
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Ingredient"
android:id="#+id/addIngredient"
android:layout_below="#+id/ingredientsList"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<TextView
android:id="#+id/directionsHeading"
android:layout_below="#+id/addIngredient"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Directions"
android:textStyle="bold|italic"
android:layout_weight="1" />
<ListView
android:id="#+id/directionsList"
android:layout_below="#+id/directionsHeading"
android:layout_width="wrap_content"
android:layout_height="195dp"
android:layout_weight="1"></ListView>
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Direction"
android:id="#+id/addDirection"
android:layout_below="#+id/ingredientsList"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/filterButton"
app:backgroundTint="#color/floatingButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:clickable="true"
android:src="#drawable/ic_filter"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="63dp"
android:layout_marginRight="16dp" />
</android.support.design.widget.CoordinatorLayout>
Main XML
<android.support.v4.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout2">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<FrameLayout
android:id="#+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</android.support.design.widget.CoordinatorLayout>
<fragment
android:id="#+id/fragment_navigation_drawer"
android:name="com.example.rory.pocketchef.Fragments.FragmentDrawer"
android:layout_width="#dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fragment_navigation_drawer"
tools:layout="#layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
I solved the issue. As the scroll view was being displayed the bottom was being cut off by the bottom action bar on the actual phone. So to solve this I added padding to the bottom of the scrollview in order to push it back up above the action bar.
The new layout it as follows
Updated working XML
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/coordinatorLayout">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="vertical"
android:paddingBottom="?android:attr/actionBarSize"> <<<-------added this line
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recipe Title"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:id="#+id/ingredientsHeading"
android:layout_below="#+id/text_input_layout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Ingredients"
android:textStyle="bold|italic"
android:layout_weight="1" />
<ListView
android:id="#+id/ingredientsList"
android:layout_below="#+id/ingredientsHeading"
android:layout_above="#+id/directionsHeading"
android:layout_width="wrap_content"
android:layout_height="195dp"
android:layout_weight="1"></ListView>
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Ingredient"
android:id="#+id/addIngredient"
android:layout_below="#+id/ingredientsList"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<TextView
android:id="#+id/directionsHeading"
android:layout_below="#+id/addIngredient"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Directions"
android:textStyle="bold|italic"
android:layout_weight="1" />
<ListView
android:id="#+id/directionsList"
android:layout_below="#+id/directionsHeading"
android:layout_width="wrap_content"
android:layout_height="195dp"
android:layout_weight="1"></ListView>
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Direction"
android:id="#+id/addDirection"
android:layout_below="#+id/ingredientsList"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="#+id/addDirection">
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Direction"
android:id="#+id/showOptionsDialog"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Direction"
android:id="#+id/saveRecipe"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_toRightOf="#+id/showOptionsDialog"
android:layout_weight="1" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/filterButton"
app:backgroundTint="#color/floatingButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:clickable="true"
android:src="#drawable/ic_filter"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="63dp"
android:layout_marginRight="16dp" />
</android.support.design.widget.CoordinatorLayout>
Add these lines in your ScrollView
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="vertical">
use weightSum for all components in your xml file,
It's android:layout_weight. Weight can only be used in LinearLayout. If the orientation of linearlayout is Vertical, then use android:layout_height="0dp" and if the orientation is horizontal, then use android:layout_width = "0dp". It'll work perfectly.
From your question -- bottom of the layout is being cut off
It is because of fixed height given to components.
EDIT -- xml added
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
tools:context="info.androidhive.materialtabs.fragments.OneFragment">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recipe Title" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="3.5"
android:orientation="vertical">
<TextView
android:id="#+id/ingredientsHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Ingredients"
android:textStyle="bold|italic" />
<ListView
android:id="#+id/ingredientsList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<Button
android:id="#+id/addIngredient"
style="#style/AppTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:enabled="true"
android:text="Add Ingredient" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="3.5"
android:orientation="vertical">
<TextView
android:id="#+id/directionsHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Directions"
android:textStyle="bold|italic" />
<ListView
android:id="#+id/directionsList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<Button
android:id="#+id/addDirection"
style="#style/AppBaseTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:enabled="true"
android:text="Add Direction" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
You put a weightsum of 1 and your scrollview is 28. You have to put something like that <LinearLayout weightsum=15>(you don't have to put 15) and then what is inside your layout you have to distribute your 15 sum. Like <TextView layout_weight=1> it means that your textview is gonna 1/15. When I use weight I also put the height or the width, depending on which one I want to play, to 0dp. For exemple if I want to play on the width <TextView width=0dp height=wrap_content weight=1>. So you have to give a weight to every child of your LinearLayout.
Hope it help.
Edit: Also ListView in a ScrollView is not a good idea, could come from here. Look this post:
How can I put a ListView into a ScrollView without it collapsing?

Organizing layouts with edit text at bottom?

I wanted to make a layout with 3 LinearLayouts. In the 2nd LinearLayout I would have a ListView and the 3rd LinearLayout I would have an EditText and Button at the bottom. This was my attempt:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/view_post"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#color/com_facebook_blue">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/view_status"/>
</LinearLayout>
<LinearLayout
android:id="#+id/view_comments"
android:layout_below="#+id/view_post"
android:layout_width="match_parent"
android:layout_height="250dp">
<ListView
android:id="#+id/lv_comments_feed"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
<LinearLayout
android:layout_below="#+id/view_comments"
android:id="#+id/send_message"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<EditText
android:id="#+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:gravity="top|left"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
Now the design looks great but when I load the app on my phone, I have 2 problems:
I don't want to hardcode the LinearLayout heights. I have looked into layout_weight but I can't seem to have these layout_weights work without running into the 2nd problem below:
When I click the EditText, the EditText is hidden even though I have declared android:windowSoftInputMode="adjustResize|stateHidden" in my activity and I'm not sure why that's happening. Also, the EditText and Button are not directly at the bottom of the screen which is what I would want. Any help is appreciated, thanks!
you don't need to add listview as child of linear layout. and avoid fill_parent & use match_parent. if first linear layout is only for textview then don't use it inside of linearlayout. or only use wrap_content instead of a specific layout_height
Here i made some changes hope it will work
<?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:orientation="vertical">
<LinearLayout
android:id="#+id/view_post"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#222dc9">
<TextView
android:id="#+id/view_status"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/send_message"
android:layout_below="#id/view_post"
></ListView>
<LinearLayout
android:id="#+id/send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:id="#+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:gravity="top|left"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
and use in Manifest with activity name is
android:windowSoftInputMode="adjustPan"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:id="#+id/view_post"
android:layout_width="match_parent"
android:background="#color/material_grey_300"
android:padding="5dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/view_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/view_comments"
android:layout_above="#+id/send_message"
android:layout_below="#+id/view_post"
android:layout_width="match_parent"
android:background="#color/material_deep_teal_200"
android:padding="10dp"
android:layout_height="match_parent">
<ListView
android:id="#+id/lv_comments_feed"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</RelativeLayout>
<LinearLayout
android:id="#+id/send_message"
android:background="#color/material_blue_grey_800"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<EditText
android:id="#+id/write_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:layout_weight="1"
android:text="send" />
</LinearLayout>
</RelativeLayout>

ListView items hide behind the EditText. Need whatsapp like chat activity

I am having trouble in my layout implementation. Whenever I click on the edittext the softinput keyboard appears and hides the listview items, what i need is that whenever soft keyboard pops up and if the listview's last item is visible, it should be brought above the edit text, if its not visible, the list should remain the way it is (the same way it is in whatsapp), heres my layout code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bg_other" >
<include
android:id="#+id/actionbar_toolbar"
layout="#layout/toolbar" />
<ListView
android:id="#+id/lv_listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/line_separator"
android:layout_below="#+id/actionbar_toolbar"
android:clipToPadding="false"
android:divider="#android:color/transparent"
android:dividerHeight="12dp"
android:paddingBottom="12dp"
android:scrollbars="none"
android:stackFromBottom="true" >
</ListView>
<View
android:id="#+id/line_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_above="#+id/ll_editText"
android:background="#1F000000"/>
<LinearLayout
android:id="#+id/ll_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:padding="8dp" >
<EditText
android:id="#+id/et_editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:hint="#string/message_hint"
android:textCursorDrawable="#drawable/cursor_color"
android:maxLines="4" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="#1F000000"/>
<Button
android:id="#+id/btn_Button_send"
android:layout_width="48dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:text="#string/cherry_send"
android:textColor="#color/orange"
android:textSize="24sp"
android:background="#android:color/transparent" />
</LinearLayout>
<Button
android:id="#+id/btn_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/ll_editText"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:background="#A0000000"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:text="2 new messages"
android:textColor="#android:color/white"
android:textSize="14sp"
android:visibility="gone" />
</RelativeLayout>
I have used window:softInputMode as adjustResize in my manifest for the activity, since using adjustPan hides the editText behind soft keyboard in some cases.
Please suggest how I can achieve this. Thanks in advance
Got the solution....
mListView.setTransctiptMode(ListView.TRANSCRIPT_MODE_NORMAL);
did the trick :)
Try LinearLayou something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/lv_listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:clipToPadding="false"
android:divider="#android:color/transparent"
android:dividerHeight="12dp"
android:paddingBottom="12dp"
android:scrollbars="none"
android:stackFromBottom="true" >
</ListView>
<View
android:id="#+id/line_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#1F000000" />
<LinearLayout
android:id="#+id/ll_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp" >
<EditText
android:id="#+id/et_editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:hint="text"
android:maxLines="4" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="#1F000000" />
<Button
android:id="#+id/btn_Button_send"
android:layout_width="48dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="#android:color/transparent"
android:textSize="24sp" />
</LinearLayout>
<Button
android:id="#+id/btn_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:background="#A0000000"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:text="2 new messages"
android:textColor="#android:color/white"
android:textSize="14sp"
android:visibility="gone" />
</LinearLayout>

Android - Messaging application layout

I am trying to reproduce the layout from the stock Android messaging app. I've done this using a list view with a custom adapter for the conversation and a fixed layout for the "send message" part. It looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" >
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/sendMsgLayout"
android:overScrollMode="always"
android:stackFromBottom="true"
android:layout_alignParentTop="true" >
</ListView>
<RelativeLayout
android:id="#+id/sendMsgLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp" >
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/list_divider" />
<EditText
android:id="#+id/messageText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toLeftOf="#+id/imageSend"
android:hint="#string/type_message"
android:maxLines="3" >
<requestFocus />
</EditText>
<ImageView
android:id="#+id/imageSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/messageText"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:src="#drawable/send" />
</RelativeLayout>
This is my latest version of the layout, I've also used a LinearLayout as the parent with weight set to 1 for the list view.
The edit text has max 3 lines. The problem comes when one line is not enough to hold the text and the edit text grows. It covers part of the list view.
I think I should scroll the list view whenever the edit text grows in dimension but I could not achieve that.
Any ideas on how to tackle this one ?
Set the listview transcriptMode to normal, alternativly alwaysScroll and as pointed out by #andreid remove android:overScrollMode="always".
android:transcriptMode="normal"
or in code:
listView.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_NORMAL);
Try this code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:orientation="vertical" >
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:stackFromBottom="true"
android:layout_weight="1" >
</ListView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/list_divider" />
<LinearLayout
android:id="#+id/sendMsgLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="20dp"
android:orientation="horizontal" >
<EditText
android:id="#+id/messageText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:hint="#string/type_message"
android:maxLines="3" >
<requestFocus />
</EditText>
<ImageView
android:id="#+id/imageSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:src="#drawable/send" />
</LinearLayout>
</LinearLayout>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
android:orientation="vertical">
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:overScrollMode="always"
android:stackFromBottom="true"
android:layout_marginBottom="5dp"/>
<LinearLayout
android:id="#+id/sendMsgLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/messageText"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="#string/type_message"
android:maxLines="3" >
<requestFocus />
</EditText>
<ImageView
android:id="#+id/imageSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/send" />
</LinearLayout>
</LinearLayout>

Android - EditText isn't filling up available space in a fragment?

I'm having an issue with my EditText (with id of body) not filling up the available space in my layout. I've been searching everywhere and experimenting with numerous resources, but I just simply can not seem to get it and have been spending hours on literally just this.. I'm guessing there is an issue with how my entire layout is set up, and probably can't just make a tweak in EditText. By the way this layout is being used in a fragment, maybe that changes things? I'm not sure, what do you guys think? Thanks for any and all help! Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title" />
<EditText android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/body" />
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="write those saucy lyrics"
android:layout_marginTop="5dp"
android:scrollbars="vertical" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnEmail"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/btnEmail"
android:alpha="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I'm looking for my design to look like this (taken from my graphical layout editor):
However on my device it looks like this(snapshot from my device):
Try this..
Change android:layout_height="wrap_content" to android:layout_height="0dp"
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical" />
// try this way,hope this will help you...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/title"/>
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="#string/body"
android:layout_marginTop="5dp"
android:scrollbars="vertical" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnEmail"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/btnEmail"
android:alpha="1" />
</LinearLayout>
</LinearLayout>
Make
android:layout_height="match_parent"
instead of
android:layout_height="wrap_content"
in Body edit text
So that it becomes
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:scrollbars="vertical" />
UPDATE:
Plz try following layout
<!-- Put the buttons at the bottom -->
<RelativeLayout
android:id="#+id/rel_lay_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Confirm" />
<Button
android:id="#+id/btnEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:alpha="1"
android:text="Emial" />
</RelativeLayout>
<!-- Put the title layout at the top of parent -->
<LinearLayout
android:id="#+id/lin_lay_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<EditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<!-- Occupy rest of the space of screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_above="#id/rel_lay_btn"
android:layout_below="#id/lin_lay_title">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Body" />
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="top"
android:layout_weight="1"
android:scrollbars="vertical" />
</LinearLayout>

Categories

Resources