I am trying to create very simple widget design. For the past two days I am still not able to complete it and I would appreciate your help.
What I am trying to do is something looks like this design:
Please note the size of the image buttons is 16pd for both height and width.
<?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:orientation="vertical"
android:gravity="center"
android:layout_margin="4dp"
android:background="#drawable/background" >
<TextView
android:id="#+id/tvDisplayer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HDisplaer"
android:textSize="25px"
android:gravity="center"/>
<TextView
android:id="#+id/tvsmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="7px"
android:gravity="center"/>
<ImageButton
android:id="#+id/imRefresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/refresh"
android:layout_gravity="left" />
<ImageButton
android:id="#+id/imOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/aboutus"
android:layout_gravity="right" />
</LinearLayout>
Wrap the ImageButtons with a RelativeLayout! Otherwise the code seems to be ok.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/imRefresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/refresh"
android:layout_alignParentLeft="true" />
<ImageButton
android:id="#+id/imOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/aboutus"
android:layout_alignParentRight="true" />
</RelativeLayout>
If the TextViews are not centered, then wrap them with another RelativeLayout, and add to each TextView this line: android:layout_centerHorizontal="true"
Try 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="match_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="50dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_centerInParent="true"
android:text="TextView" />
</RelativeLayout>
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/relativeLayout1"
android:src="#drawable/black" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageButton2"
android:src="#drawable/black" />
Just increase the height of the 2nd relative layout to bring it down.
Try this:
Just use two LinearLayout one for horizontal and other for vertical.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_margin="4dp"
android:background="#drawable/background" >
<TextView
android:id="#+id/tvDisplayer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HDisplaer"
android:textSize="25px"
android:gravity="center"/>
<TextView
android:id="#+id/tvsmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="7px"
android:gravity="center"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center"
android:layout_margin="4dp"
>
<ImageButton
android:id="#+id/imRefresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left" />
<ImageButton
android:id="#+id/imOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right" />
</LinearLayout>
</LinearLayout>
Related
The following is the code of main.xml, which i have used to create a row adapter for JSON
<?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:padding="4dp"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="0.88"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="pumpName"
android:id="#+id/tvPump" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Time"
android:id="#+id/tvTime"
android:gravity="center_vertical" />
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ivIcon"
android:src="#drawable/yes" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
The above code produces no error but the Time TextView does not come at the center.
I have tried android:gravity="center" but it did not work.
This is the image of my android studio
Relative Layout could come in handy here like so:
<?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:padding="4dp">
<TextView
android:id="#+id/tvPump"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="pumpName"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="Time"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:layout_width="wrap_content"
android:id="#+id/ivIcon"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_height="wrap_content"
android:src="#drawable/yes" />
</RelativeLayout>
I'm beginner in android,and want to write xml file show two button center of screen horizontally,write this code:
<?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:layout_centerHorizontal="true">
<TextView android:text="#+id/TextView01" android:id="#+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<Button
android:id="#+id/allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/TextView01"
android:text="Allow"/>
<Button
android:id="#+id/deny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/allow"
android:layout_alignTop="#id/allow"
android:text="Deny"/>
</RelativeLayout>
that show me this:
but i want this:
Try this code. It will give desired layout
<?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/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/TextView01" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/allow"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Allow" />
<Button
android:id="#+id/deny"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_height="wrap_content"
android:text="Deny" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Try this:
<Button
android:id="#+id/allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="Allow"/>
<Button
android:id="#+id/deny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/allow"
android:layout_alignTop="#id/allow"
android:text="Deny"/>
First try changing your RelativeLayout height to android:layout_height="match_parent".
After that you could put both buttons in a LinearLayout like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerInParent="true">
<Button
android:id="#+id/allow"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Allow" />
<Button
android:id="#+id/deny"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_height="wrap_content"
android:text="Deny" />
</LinearLayout>
<?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" >
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some text or #string reference from strings.xml" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<Button
android:id="#+id/allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Allow" />
<Button
android:id="#+id/deny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Deny" />
</LinearLayout>
</RelativeLayout>
I have the following code with which i am trying to display at right corner of the title bar but its getting displayed in center.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:gravity="center_vertical"
android:background="#drawable/formheader">
<ImageView
android:id="#+id/header"
android:background="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ShowRoom"
android:textColor="#android:color/black"
android:textStyle="bold"/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:background="#drawable/menu"/>
</LinearLayout>
These are the properties of RelativeLayout, So it won't work with LinearLayout.
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
Add android:layout_weight="1" to TextView.
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ShowRoom"
android:textColor="#android:color/black"
android:textStyle="bold" />
Change it like 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="35dip"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="ShowRoom"
android:textColor="#android:color/black"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"
android:clickable="true" />
</LinearLayout>
You can do it in 2 ways,
Follow #prag's answer if you want to continue with LinearLayout.
Another simplest way is to use RelativeLayout like below,
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:gravity="center_vertical"
android:background="#drawable/formheader">
<ImageView
android:id="#+id/header"
android:background="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/header"
android:layout_centerVertical="true"
android:text="ShowRoom"
android:textColor="#android:color/black"
android:textStyle="bold"/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:clickable="true"
android:background="#drawable/ic_launcher"/>
</RelativeLayout>
Try this 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="35dip"
android:orientation="horizontal" >
<ImageView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="ShowRoom"
android:textColor="#android:color/black"
android:textStyle="bold" />
<View
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1" >
</View>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#drawable/ic_launcher"
android:clickable="true" />
</LinearLayout>
Note: Replace my drawable image with yours. Hope this resolves your problem
my xml code for list view's row is
<?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:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:orientation="vertical" >
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" />
<TextView
android:id="#+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="2"
android:gravity="center" >
<ImageView
android:id="#+id/iv_image"
android:layout_width="50dp"
android:layout_height="40dp"
android:background="#drawable/app_icon_17"
android:contentDescription="#string/empty" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="2"
android:gravity="center" >
<Button
android:id="#+id/btn_delete"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/btn_delete_new"
android:focusable="false" />
</LinearLayout>
</LinearLayout>
I want the last button with id btn_delete to stay right aligned. And its showing as I wanted in "graphical layout" while designing. But when I run it, on emulator it's not working.
See the output :
So why the delete button not getting right aligned?
Use this, using relative layout
<?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" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" >
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" />
<TextView
android:id="#+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_name"
android:layout_marginLeft="10dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" >
<Button
android:id="#+id/btn_delete"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/btn_delete_new"
android:focusable="false" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_toLeftOf="#+id/rl_btn" >
<ImageView
android:id="#+id/iv_image"
android:layout_width="50dp"
android:layout_height="40dp"
android:background="#drawable/app_icon_17"
android:contentDescription="#string/empty" />
</RelativeLayout>
</RelativeLayout>
You seem to have misunderstood layouts, those embedded LinearLayouts aren't needed. Use a RelativeLayout, e.g.:
<?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" >
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp" />
<TextView
android:id="#+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp" />
<ImageView
android:id="#+id/iv_image"
android:layout_width="50dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/tv_time"
android:background="#drawable/app_icon_17"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/btn_delete"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:background="#drawable/btn_delete_new"
android:focusable="false" />
</RelativeLayout>
As we can see that you have assign weight to your row layout.
If you assign weight your parent layout you just need to set accordingly height or with 0dp.
In your case android:layout_width="0dp"
but when you have child layout of that weighted layout then you must give that layouts property as fill_parent i.e: button's android:layout_height="fill_parent"
So if you don't want to change your parent layout and want to work with existing code you can try below code.
<?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:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:orientation="vertical" >
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" />
<TextView
android:id="#+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
>
<ImageView
android:id="#+id/iv_image"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#drawable/icon"
android:contentDescription="#string/app_name" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2" >
<Button
android:id="#+id/btn_delete"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#drawable/icon"
android:focusable="false" />
</LinearLayout>
</LinearLayout>
Change this
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="2"
android:gravity="center" >
<Button
android:id="#+id/btn_delete"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/btn_delete_new"
android:focusable="false" />
</LinearLayout>
to
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_delete"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="right"
android:background="#drawable/btn_delete_new"
android:focusable="false" />
</LinearLayout>
You were applying android:layout_gravity="right" to layout. Instead, you should apply it to a button inside layout. And I don't think you need weight 2 for that layout. But you can add it if its required for you. Hope it helps.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical" >
<Button
android:id="#+id/btn_delete"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="right"
android:gravity="right"
android:background="#drawable/btn_delete_new"
android:focusable="false" />
</LinearLayout>
I want to add a custom Dialog, but I have problems creating a xml like I want..
Here what I imagine:
[IMAGE][TEXT]
[SCROLLABLETEXT]
[BUTTON][BUTTON][BUTTON]
And my current xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imgMentor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/changelogicon" />
<TextView
android:id="#+id/tvSubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="--"
android:textColor="#FFF"
android:textSize="20px" />
</LinearLayout>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:padding="10dp" >
<TextView
android:id="#+id/tvExplanation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dip"
android:text="--"
android:textColor="#FFF" />
</ScrollView>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:baselineAligned="true" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
</LinearLayout>
Image, text and scrollable text looking great, but if the text in the middle gets too long and become scrollable, my buttons are gone..
What did I do wrong?
EDIT:
my Solution:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/changelogicon" />
<TextView
android:id="#+id/tvSubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imgIcon"
android:layout_marginBottom="15dp"
android:layout_toRightOf="#+id/imgIcon"
android:text="--"
android:textColor="#FFF"
android:textSize="20px" />
<ScrollView
android:id="#+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button1"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imgIcon"
android:layout_marginTop="20dp" >
<TextView
android:id="#+id/tvExplanation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dip"
android:text="--"
android:textColor="#FFF" />
</ScrollView>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Button" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Button" />
</RelativeLayout>
Use a RelativeLayout rather than a LinearLayout as the top-level element in your view hierarchy. LinearLayouts don't do very well at handling this sort of "fill the middle" scenario.
With a RelativeLayout you can align your buttons with the bottom, your text/image with the top and then align your ScrollView to be below the text/image and above the buttons, stretching it accordingly.
Take a look at the "Hello RelativeLayout" tutorial for more info.
Quick SO tip: If you increase your accept rate, more people are likely to answer your question.