EditText on the bottom of Relative Layout overlays views under it - android

LinearLayout with editText on the bottom overlays the content of scrollView, which is filled programmatically.
How to avoid this please?
I have simplified the XML in vain in my first version of this message.
I have added the full code now
I'd like to keep my editText height expandable.
<?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="fill_parent"
android:background="#color/backNormal"
android:orientation="vertical"
>
<include layout="#layout/adview"
android:layout_alignParentTop="true"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal"
android:background="#color/back1"
android:layout_below="#+id/adView"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:id="#+id/textChatSubjectTitle"
android:text='Subject'
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_weight="5"
android:layout_height="wrap_content"
android:textColor="#color/text1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:orientation="horizontal"
>
<TextView
android:id="#+id/textChatActn"
android:text='0'
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/textWhite"
android:background="#color/gray"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
<TextView
android:id="#+id/textChatUsers"
android:text='users'
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/darkGray"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="normal"
/>
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/imageChatImageTitle"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="right"
/>
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollChat"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/backNormal"
android:orientation="vertical"
android:layout_below="#+id/top"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearChat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
</ScrollView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/back1"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
>
<ImageView
android:id="#+id/buttonClip"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:src="#drawable/clip32"
android:layout_weight="1"
android:layout_gravity= "center_vertical|center_horizontal"
/>
<EditText
android:id="#+id/editChatMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="textMultiLine|textCapSentences"
android:minLines="1"
android:gravity="top|left"
android:maxLines="5"
android:maxLength="500"
android:layout_marginRight="5dp"
android:text=''
android:layout_gravity= "center_vertical|center_horizontal"
android:textColor="#color/text1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="5"
android:background="#drawable/edit"
android:scrollHorizontally="false"
android:cursorVisible="true"
android:textCursorDrawable="#null"
/>
<Button
android:id="#+id/buttonChatSend"
android:text='>'
android:layout_marginRight="5dp"
android:gravity="center"
android:layout_gravity= "center_vertical|center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/darkGray"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:background="#drawable/button_normal"
/>
</LinearLayout>
</RelativeLayout>
Any ideas please?
Thanks!

I suggest using Relative layout for parent. And then add the rule above.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/llButton"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/llButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:id="#+id/editMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="top|left"
android:inputType="textMultiLine|textCapSentences"
android:maxLines="5"
android:minLines="3"
android:scrollHorizontally="false" />
<Button
android:id="#+id/buttonSend"
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>

Please try the below code, if it solves your problem.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="1200dp"
android:background="#ff0000"
android:orientation="vertical"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/editMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="#drawable/edit"
android:gravity="top|left"
android:inputType="textMultiLine|textCapSentences"
android:maxLines="5"
android:minLines="3"
android:textColor="#color/text1"
android:scrollHorizontally="false"
/>
<Button
android:id="#+id/buttonSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="#drawable/button_normal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</ScrollView>

Related

LinearLayout not work with RelativeLayout

I want to create following layout.
--------------------------------
Title
Summary Info
[Get Direction][Call][More Info]
--------------------------------
I code following layout but buttons not showing. I have no idea why LinearLayout works like FrameLayout so the RelativeLayout hides buttons. Did I miss something here?
I am using support library 22.1
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/location_card_height">
<ImageView android:id="#+id/cardImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom" >
<TextView android:id="#+id/title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:singleLine="true"
android:hint="Title" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/title">
<TextView android:id="#+id/info"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearance"
android:singleLine="true"
android:hint="Info"
android:layout_alignParentRight="true"
android:ellipsize="end" />
<TextView android:id="#+id/summary"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearance"
android:singleLine="true"
android:hint="Summary"
android:layout_toLeftOf="#id/info"
android:ellipsize="end" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/panelAction"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnDirection"
android:text="#string/get_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnCall"
android:text="#string/label_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnMoreInfo"
android:text="#string/more_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
Your relative layout has been set to match_parent for it height!
change it to wrap_content
that should help you
or put it in a LinearLayout
something like this :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/location_card_height">
<ImageView android:id="#+id/cardImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:orientation="vertical" >
<RelativeLayout
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom" >
<TextView android:id="#+id/title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:singleLine="true"
android:hint="Title" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/title">
<TextView android:id="#+id/info"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearance"
android:singleLine="true"
android:hint="Info"
android:layout_alignParentRight="true"
android:ellipsize="end" />
<TextView android:id="#+id/summary"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearance"
android:singleLine="true"
android:hint="Summary"
android:layout_toLeftOf="#id/info"
android:ellipsize="end" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/panelAction"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:id="#+id/btnDirection"
android:text="#string/get_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnCall"
android:text="#string/label_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnMoreInfo"
android:text="#string/more_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
If you are fine With Linearlayout Then Here is Your XML file
<?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"
android:weightSum="1" >
<ImageView
android:id="#+id/cardImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="center"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
android:singleLine="true"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/summary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/info"
android:layout_weight="1"
android:ellipsize="end"
android:hint="Summary"
android:singleLine="true"
android:text="Summary"
android:textAppearance="?android:attr/textAppearance" />
<TextView
android:id="#+id/info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="right"
android:hint="Info"
android:singleLine="true"
android:text="Info"
android:textAppearance="?android:attr/textAppearance" />
</TableRow>
</LinearLayout>
<LinearLayout
android:id="#+id/panelAction"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="bottom" >
<Button
android:id="#+id/btnDirection"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Get_direction" />
<Button
android:id="#+id/btnCall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="call" />
<Button
android:id="#+id/btnMoreInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="more_info" />
</LinearLayout>

Place button below editfield in relative layout

Hi all I have to add 2 Buttons below editfield. I had tried it using relativelayout. But it is not added exactly below mention position.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E8E8E8" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="User Name"
android:textStyle="bold" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="Description"
android:textStyle="bold" />
<EditText
android:id="#+id/des"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/des"
android:padding="10dip">
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Submit" />
<Button
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/submit"
android:text="Cancel" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Here I want to add these two buttons exactly below "des" editfield. Thanks in advance
Currently it displays like . But I want these two buttons exactly below last editfield with equal size.
You have just add on your relative layout:
layout_gravity on right and width make on wrap_content. like this
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#id/des" android:layout_gravity="right"
android:padding="10dip">
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Submit" />
<Button
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/submit"
android:text="Cancel" />
</RelativeLayout>
Output looks like:
Ist think you are doing wrong is that : ScrollView never contains Relative Layout as a direct child. it use LinearLayout as a direct child .
use this code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="User Name"
android:textStyle="bold" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="Description"
android:textStyle="bold" />
<EditText
android:id="#+id/des"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/des"
android:orientation="horizontal"
android:padding="10dip" >
<Button
android:id="#+id/submit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Submit" />
<Button
android:id="#+id/cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Try this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E8E8E8" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="User Name"
android:textStyle="bold" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="Description"
android:textStyle="bold" />
<EditText
android:id="#+id/des"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/des"
android:padding="10dip">
<Button
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Cancel" />
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/cancel"
android:text="Submit" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Try this:
One more thing when you want to do stuff like this, try to see in graphical layout and move elements in that to position you want. Most of time it will work as expected and you can get idea of place too.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E8E8E8" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="User Name"
android:textStyle="bold" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="Description"
android:textStyle="bold" />
<EditText
android:id="#+id/des"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/des"
android:padding="10dip" >
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Submit" />
<Button
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/submit"
android:layout_alignBottom="#+id/submit"
android:layout_alignParentRight="true"
android:text="Cancel" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
In your case its not possible because you are trying to place a button relative to EditText which is placed inside a LinearLayout, you can place the button relative to linearlayout but not its ChildViews.
Try to bring all the Views inside a single relative layout and place all the Views relative to each other.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E8E8E8" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="User Name"
android:textStyle="bold" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="Description"
android:textStyle="bold" />
<EditText
android:id="#+id/des"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/des"
android:padding="10dip" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal" >
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:text="Submit" />
<Button
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
Hope this will solve your problem
android:layout_below="#id/des" That des is present in LinearLayout, IF you want to give that way, Same RelativeLyout should be given within the layout that des is present and Their parent should be relative layout, to use parementers such as below or above(i.e., with relative to other widget)

Top views in scrollView are not visible in landscape screen

The problem is that in landscape screen position
I can't slide to see top textView.
And the image on the top is visible only partly.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/backNormal"
android:orientation="vertical"
>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/backNormal"
android:orientation="vertical"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/backNormal"
android:orientation="vertical"
android:layout_gravity="center_horizontal|center_vertical"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/backNormal"
android:orientation="horizontal"
android:layout_gravity="center_horizontal|center_vertical"
android:weightSum="6"
>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/backNormal"
android:orientation="vertical"
android:layout_weight="4"
android:layout_gravity="center_horizontal|center_vertical"
>
<TextView
android:id="#+id/textNameTitle"
android:gravity="center"
android:text='Your profile'
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/text_style_title"
/>
<ImageView
android:id="#+id/imageNameAvatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true"
android:src="#drawable/clip32"
/>
<EditText
android:id="#+id/editName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="1"
android:minLines="1"
android:maxLines="1"
android:maxLength="25"
style="#style/edit_style"
android:layout_gravity="left"
android:background="#drawable/edit"
android:inputType="textCapSentences"
android:cursorVisible="true"
android:textCursorDrawable="#null"
/>
<TextView
android:id="#+id/textInfoGenderTitle"
android:gravity="center"
android:text='Gender'
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
style="#style/text_style_normal"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:weightSum="4"
>
<Button
android:id="#+id/buttonInfoMale"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text='M'
style="#style/button_style_normal"
/>
<TextView
android:id="#+id/textInfoGender"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="center"
android:text='Unknown'
android:background="#color/backDark1"
style="#style/text_style_normal"
/>
<Button
android:id="#+id/buttonInfoFemale"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:text='F'
style="#style/button_style_normal"
/>
</LinearLayout>
<TextView
android:id="#+id/textInfoYearTitle"
android:gravity="center"
android:text='Year'
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
style="#style/text_style_normal"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:weightSum="4"
>
<Button
android:id="#+id/buttonInfoYearMinus"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text='-'
style="#style/button_style_normal"
/>
<TextView
android:id="#+id/textInfoYear"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="center"
android:text='Unknown'
android:background="#color/backDark1"
style="#style/text_style_normal"
/>
<Button
android:id="#+id/buttonInfoYearPlus"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:text='+'
style="#style/button_style_normal"
/>
</LinearLayout>
<ProgressBar
android:id="#+id/progressBarName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity= "center_vertical|center_horizontal"
/>
<Button
android:id="#+id/buttonNameReg"
android:text='Registration'
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
style="#style/button_style_normal"
/>
<TextView
android:id="#+id/textNameResult"
android:gravity="center"
android:text=''
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/text_style_normal"
/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Any advices please! Thanks!
Sorry for the text below.
The site said that my post is mostly code...
text text text text
text text
text text

When focus on the edite text resize layout

when i press on the edit text the layout become re-size. What i want is not to change the layout size when i press on the keyboard
I tried
android:windowSoftInputMode="stateVisible|adjustPan"
Refer from below link
http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
Don't make any difference
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bbbbbb"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1"
android:background="#0486CC" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".34"
android:src="#drawable/logo" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".32" />
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".16"
android:background="#drawable/newmenu"
android:onClick="MenuStaffBtnClick" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".18"
android:background="#drawable/menu_sync"
android:onClick="MenuSynBtnClick" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".2" >
<EditText
android:id="#+id/etNamecheck"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_weight=".6"
android:ems="10"
android:hint="Name" />
<RadioGroup
android:id="#+id/rgSearch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".4"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/rbID"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/rbName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".7"
android:orientation="vertical" >
<ListView
android:id="#+id/LVitems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#bbbbbb"
android:dividerHeight="5dp" >
</ListView>
</LinearLayout>
try this layout code and add android:windowSoftInputMode="stateVisible|adjustPan" in android manifest file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ScrollView
android:id="#+id/scrolllayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SignIn"
android:textColor="#000000"
android:layout_marginTop="10dp"
android:textSize="20dp"
/>
<EditText
android:id="#+id/userid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textColor="#000000"
android:hint="type username" />
<EditText
android:id="#+id/passwordid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="type password"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textColor="#000000"
android:inputType="textPassword" />
<Button
android:id="#+id/loginid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textColor="#color/list_item_title"
android:text="Signin"
android:textSize="20dp"
android:background="#drawable/btngradient"
/>
<Button android:id="#+id/registerid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:textSize="20dp"
android:text=" Register"
android:gravity="center"
android:background="#drawable/btngradient"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:textColor="#FFFFFF"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>

LinearLayout not rendering

I want to create a login screen. I want to have the heading at the top, leave some white space and then have the user name and passwords each in one line. Then, I want to leave some more white space at the bottom.
Currently, I haven't tried to put the password TextView and EditTect in a single line because there is some error with the LinearLayout corresponding to the user name due to which it is not rendering. Could you please help me figure out? My XML file is below -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="2"
android:gravity="center_horizontal"
android:text="#string/welcome_message"
android:textSize="20sp" />
<View
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="4" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="4"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="User Name" />
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="0sp"
android:layout_weight="1"
android:text="Password" />
<EditText
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="1"
android:inputType="textPassword" />
<View
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="4" />
</LinearLayout>
Take a look if this what are you looking for:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<View
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="0.5" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="3"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="welcome_message"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="1" >
<TextView
android:id="#+id/text_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:lines="1"
android:text="Login:"
android:textSize="13dp" />
<EditText
android:id="#+id/edt_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="0.2"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="4" >
<TextView
android:id="#+id/text_senha"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:maxLines="1"
android:text="Senha:" />
<EditText
android:id="#+id/edt_senha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="0.2"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="0.5" />
</LinearLayout>
use layout margin and padding settings to leaving space for views.
i recommend using relative layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="2"
android:layout_marginTop="30dip"
android:gravity="center_horizontal"
android:text="welcome_message"
android:textSize="20sp" />
<View
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="4" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:padding="10dip"
android:weightSum="2"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="User Name" />
<EditText
android:layout_width="wrap_content" android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:padding="10dip"
android:weightSum="2"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Password" />
<EditText
android:layout_width="wrap_content" android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>

Categories

Resources