I have a very simple layout that i designed to achieve the tool bar at the top of the screen. I am using weights here to fit all devices. Giving like 11 to the tool bar and 89 to the content body. That will fit all screens no matter what.
Problem:
I have a scroll view inside the content body and inside that scroll view i have like 4 EditText views. When i click the last EditText to type into it my layout gets pushed up specially the tool bar for which i have to use weights.
Now please don't tell me not to use weights, just tell me how can i fix it. how can i stop the layout pushing up? Just like Gmail Client. when you are typing the header is not pushed up, stays there that you can save or send the email.
Main.xml:
<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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#ffe234"
android:layout_weight="11" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:text="Memories" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="89" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minLines="6"
android:ems="10" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
In your manifest you want you add edit or add the android:windowSoftInputMode. Then set it to adjustNothing, if you don't want the screen to adjust.
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan|adjustNothing">
</activity>
Documentation
android:windowSoftInputMode
http://developer.android.com/guide/topics/manifest/activity-element.html
adjustNothing 0x30 Don't resize or pan the window to make room for the soft input area; the window is never adjusted for it.
http://developer.android.com/reference/android/R.attr.html#windowSoftInputMode
Please use weight ="0.11" and weight ="0.89"
instead of
weight ="11" amd weight ="89" in your layout.
The layout is pushing up because scroll view adjusts to the entire screen when input method appears.
Try using ScrollView's property isScrollContainer by setting it to false.
It should look like the following:
...
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="false" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minLines="6"
android:ems="10" />
</LinearLayout>
</ScrollView>
...
If this does not help consider setting proper windowSofInputMode in your activity in AndroidManifest.xml.
Related
I have some problem in my layout width edit-text
here are screenshots which describe my problem
1. normal layout (all views are inside the LinearLayout)
2. I want layout below when user input many text lines inside the Edit Text
3. But When user enter many text lines.. my layout looks like below.
I want the Edit Text should be stretched until only ImageView meets the bottom ViewGroup.
but, more entering text lines, more being increased the height of Edit Text so, i cannot see Image View.
i'd appreciate it if you give me any solution.
LinearLayout handles this sort of layouts great. You can use the attribute android:layout_weight="1" within a LinearLayout to set the priority of the space you want the object to take.
The official documentation describe it best:
developer.android.com
Take RelativeLayout as your parent layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="?actionBarSize"
android:orientation="vertical">
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:inputType="textMultiLine"
android:scrollbars="vertical"/>
<ImageView
android:id="#+id/imageView1"
android:layout_marginBottom="?actionBarSize"
android:layout_width="match_parent"
android:layout_weight="0.1"
android:layout_height="?actionBarSize" />
</LinearLayout>
<View
android:id="#+id/view1"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:layout_alignParentBottom="true" />
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/bottomGroup"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<RelativeLayout
android:id="#+id/bottomGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
I have a layout, code below
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--some stuff here-->
<LinearLayout
android:id="#+id/layout1"
android:layout_alignParentBottom="true"
android:layout_above="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitStart"
android:layout_marginLeft="5dp"
style="#style/Base.Widget.AppCompat.Button.Borderless"
android:src="#drawable/ic_menu_send"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout2"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!--some stuff here-->
</LinearLayout>
</RelativeLayout>
In the above code when keyboard is show i want layout2 to stay in the bottom and layout1 to go up with keyboard. if i add android:windowSoftInputMode="adjustPan|adjustResize" both layout stay in bottom. please help
as you can say this is not work
android:windowSoftInputMode="adjustPan|adjustResize"
just change it this
android:windowSoftInputMode="stateHidden"
and one more thing in your below layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--some stuff here-->
<LinearLayout
android:id="#+id/layout1"
android:layout_alignParentBottom="true"
android:layout_above="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitStart"
android:layout_marginLeft="5dp"
style="#style/Base.Widget.AppCompat.Button.Borderless"
android:src="#drawable/ic_menu_send"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout2"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#color/colorPrimary">
<!--some stuff here-->
</LinearLayout>
</RelativeLayout>
Keep in Mind :
When you have applied this property android:layout_above="#+id/layout2" to layout1 of your LinearLayout then remove this property android:layout_alignParentBottom="true" you don't require it.
So Now that look like this
<LinearLayout
android:id="#+id/layout1"
android:layout_above="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Note : I am giving background color and specific height to
LinearLayout 2 for your Understandment.
Output :
Normal Screen
KeyBoard Open Screen.
ImProve :
see the upper Image I make Red Mark that property create the problem otherwise every thing is work fine.
Please use this, and tell me if you find any difficulties
<?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">
<!--some stuff here-->
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/layout2"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5" />
<ImageButton
style="#style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:scaleType="fitStart"
android:src="#drawable/ic_menu_send" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<!--some stuff here-->
</LinearLayout>
</RelativeLayout>
Use different themes for both the layouts.
such as:
One theme refers to adjustPan for windowSoftInputMode attribute.
and another theme refers to adjustResize for windowSoftInputMode attribute.
The fastest way is hide the layouts when soft keyboard is enable and show them again when the soft keyboard is disabled (layout2 on the xml)
Remove this Line as well
android:windowSoftInputMode="adjustPan|adjustResize"
it will work , this is just a simple way , I'm still searching for you
put this line in your manifest file.
android:windowSoftInputMode="stateHidden"
Remove the android:windowSoftInputMode="adjustPan|adjustResize"
And then Hide the layout2 programmatically when soft keyboard open. When soft keyboard close, again make the layout2 visible.
This will give user an experience exactly you want.I'm not shure there is any other way. But Keep searching. good Luck
How can I format a header, a list, and an EditText so that the EditText is a fixed single line and always visible?
Here is my layout with only one list entry - EditText fills the rest of the screen which looks bad.
Here is the layout with several list entries - the soft keyboard hides the text being typed. I was typing in Wayne.
I have tried a various Linear and Relative layouts. Here is my current Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/select_child_header"
style="#style/headerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/start_blue"
android:text="Which child did you take a picture of?" />
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/modchild_fragment"
android:name="com.chex.control.ChildList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/select_child_header"
android:focusable="true"
android:focusableInTouchMode="true" >
</fragment>
<EditText
android:id="#+id/new_child"
style="#style/editTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#id/modchild_fragment"
android:hint="new child name"
android:inputType="text"
android:singleLine="true" />
</RelativeLayout>
I appreciate any advice on how to format this screen.
For this you have a two options one is In textview there is a tag called android:singleLine="true" if you do like this the text comes in a single line and it miss the some text and show some dots..
And another way is you have to decrease the fontsize.. by using this tag..android:textSize="3sp"
Try this way
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/select_child_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Which child did you take a picture of?" />
<fragment
android:id="#+id/modchild_fragment"
android:name="com.chex.control.ChildList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:focusable="true"
android:focusableInTouchMode="true" >
</fragment>
<EditText
android:id="#+id/new_child"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#id/modchild_fragment"
android:hint="new child name"
android:inputType="text"
android:singleLine="true" />
</LinearLayout>
Set
android:ellipsize=end
android:singleLine="true"
Change the order and positioning of your elements:
add first the header on top
add the bottom edittext
add the fragment in-between
Something like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/select_child_header"
style="#style/headerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/start_blue"
android:text="Which child did you take a picture of?" />
<EditText
android:id="#+id/new_child"
style="#style/editTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:hint="new child name"
android:inputType="text"
android:singleLine="true" />
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/modchild_fragment"
android:name="com.chex.control.ChildList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/new_child"
android:layout_below="#id/select_child_header"
android:focusable="true"
android:focusableInTouchMode="true" >
</fragment>
</RelativeLayout>
Add
android:maxLines="1"
to your EditText, to get desired number of lines .
You can set the static height to the Fragment. So that if your list item say for example, one or more than 5 also, your edit text constitutes the bottom layer of fragment.
Also, you can set android:singleLine="true" property to edittext.
There is a very high possibility that a question similar to this has been asked earlier, but I couldn't figure out the related keywords to find the same.
I am making an application, and the layout I designed is:
<LinearLayout 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"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".Scheduler" >
<EditText
android:id="#+id/addressee"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/addresseeHint"
android:inputType="number" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2" >
<EditText
android:id="#+id/date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/scheduleDate"
android:inputType="date" />
<EditText
android:id="#+id/time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/scheduleTime"
android:inputType="time" />
</LinearLayout>
<EditText
android:id="#+id/smsText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top"
android:hint="#string/smsTextHint"
android:inputType="text" />
<Button
android:id="#+id/scheduleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="#string/scheduleTextButton" />
</LinearLayout>
The layout which appears is as below:
What I want will look something like this:
The problem is the Button at the bottom (id:scheduleText) disappears, reason being the layout_height parameter of the EditText set just above it is fill_parent. But I guess I can't provide any particular value to it as then the layout will look different on different devices ?
How can I fix this bug ?
Thanks
Hi your EditText has a height of fill parent which makes it fill the parent and the button won't be visible so make it like this:
<EditText
android:id="#+id/smsText"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="#string/smsTextHint"
android:inputType="text" />
UPDATE:
I updated the answer to extend the edit text and fill the screen but let space for the button as well. The trick is to use weight..
I have created a relative layout with 3 listviews. At top I have a editText field. In the middle there is a scrollview that fills upp all left-over space. At the bottom I have placed a button. The thing is, when I do an input in the editText field, the keyboard shows up and then the button is moved and placed ontop of the keyboard. It seems like the button allways sticks to the bottom of the view that is "left", but I want it to remain at the bottom of the original window.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/ll_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<TextView
android:id="#+id/tv_course_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_view_course_name"
android:textStyle="bold" />
<EditText
android:id="#+id/et_course_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_save_course_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="saveCourse"
android:text="#string/button_save_course" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_course_table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/ll_save_course_button"
android:layout_below="#id/ll_name" >
</LinearLayout>
</RelativeLayout>
Inside your manifest file,
<activity
android:name=".HomeActivity"
android:windowSoftInputMode="stateHidden|adjustPan" >
NOTE:
here,I have used HomeActivity,you need to specify the activity name in which you are setting the above layout xml file.
Try this:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="saveCourse"
android:gravity="bottom"
android:text="#string/button_save_course" />
or use this
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);