For some reason I'm having a hell of a time with designing using eclipse and android SDK. Making layouts is painfully hard and not as easy as WPF/Visual Studio.
I am trying to accomplish the following:
Top: what I have
Bottom: what I want to achieve
http://imgur.com/AsaTuGq
Current code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:textIsSelectable="false"
android:id="#+id/line1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:textSize="18sp"
android:layout_weight="1"
android:textStyle="bold"
/>
<TextView
android:textIsSelectable="false"
android:id="#+id/line2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="18sp"
/>
<TextView
android:textIsSelectable="false"
android:id="#+id/line3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:textSize="18sp"
/>
</LinearLayout>
Edit:
I've also tried using Vertical LinearLayout within a Horizontal LinearLayout but that just produced a lot of errors.
Edit2:
What's with the negative rating?
Edit3:
Tried this link: http://android-developers.blogspot.ca/2009/02/android-layout-tricks-1.html
Replacing the image with a textview but the date just aligns with the top row.. hmm
You should use a RelativeLayout:
<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="wrap_content"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="false"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
I would suggest a RelativeLayout for this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:textIsSelectable="false"
android:id="#+id/line1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textSize="18sp"
android:layout_weight="1"
android:textStyle="bold"
android:layout_alignParentLeft="true"
/>
<TextView
android:textIsSelectable="false"
android:id="#+id/line2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_below="#_id/line1"
/>
<TextView
android:textIsSelectable="false"
android:id="#+id/line3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_alignParentRight="true"
android:textSize="18sp"
/>
</RelativeLayout>
Changes:
Changed LinearLayout to RelativeLayout used android:layout_alignParentLeft="true" for the first two lines and android:layout_below="#+id/line1" for the second line. Moved the date to the right with android:layout_alignParentRight="true" and android:gravity="center_vertical" Hope this works for what you need.
Related
i've got a ListView with a custom adapter so i can customize the single row. I would create a view in the layout on the left that has as height all row height, and as width something like 5dp. So it will be like a little "strip" on the left of each row in the listview. I tried in this way
<?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:layout_margin="5dp"
android:background="#layout/cardwhite"
android:orientation="vertical" >
<TextView
android:id="#+id/first"
android:layout_toRightOf="#+id/viewlist"
android:layout_marginLeft="5dp"
android:textSize="15dp"
android:fontFamily="sans-serif-light"
android:text="Partenza "
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:id="#id/viewlist"
android:gravity="left"
android:layout_width="5dp"
android:background="#52BD4F"
android:layout_margin="5dp"
android:layout_height="match_parent"
/>
<TextView
android:id="#+id/second"
android:layout_toRightOf="#id/viewlist"
android:layout_below="#id/first"
android:textSize="15dp"
android:layout_marginLeft="5dp"
android:fontFamily="sans-serif-light"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
But using android:layout_height="match_parent" or android:layout_height="wrap_content" not works and the strip doesn't appear. If i write android:layout_height="20dp" it goes but of course it's not "dynamic". I don't understand why it desappears.. Any ideas?
Please modify the layout accordingly. I have already done this one, so I'm just pasting it. You just need to make use of android:layout_alignBottom and android:layout_alignTop with proper id inside your View. Here is the screen shot !
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e5e4e2" >
<RelativeLayout
android:id="#+id/relative_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/btn_normal" >
<TextView
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignBottom="#+id/tv_type"
android:layout_alignTop="#+id/tv_dayName"
android:background="#00ff00" />
<TextView
android:id="#+id/tv_dayName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:layout_marginLeft="5dp"
android:text="Monday"
android:textColor="#000000"
android:textSize="14sp" >
</TextView>
<TextView
android:id="#+id/tv_dateNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:text="23"
android:textColor="#000000"
android:textSize="14sp" >
</TextView>
<TextView
android:id="#+id/tv_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_dayName"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:layout_marginLeft="5dp"
android:text="Mark Attendance"
android:textColor="#000000"
android:textSize="12sp" >
</TextView>
<TextView
android:id="#+id/tv_monthName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_dateNumber"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:text="Apr-14"
android:textColor="#000000"
android:textSize="12sp" >
</TextView>
</RelativeLayout>
<!--
<TextView android:id="#+id/tv_line"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:background="#drawable/text_line"
android:layout_below="#+id/relative_row"/>
-->
</RelativeLayout>
<?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:layout_margin="5dp"
android:background="#layout/cardwhite"
android:orientation="vertical" >
<TextView
android:id="#+id/first"
android:layout_toRightOf="#+id/viewlist"
android:layout_marginLeft="5dp"
android:textSize="15dp"
android:fontFamily="sans-serif-light"
android:text="Partenza "
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:id="#id/viewlist"
android:gravity="left"
android:layout_alignTop="#+id/first"
android:layout_alignBottom="#+id/second"
android:layout_width="5dp"
android:background="#52BD4F"
android:layout_margin="5dp"
android:layout_height="match_parent"
/>
<TextView
android:id="#+id/second"
android:layout_toRightOf="#id/viewlist"
android:layout_below="#id/first"
android:textSize="15dp"
android:layout_marginLeft="5dp"
android:fontFamily="sans-serif-light"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
Dont use relative layout just linearLayout
sample:
Beware that I dont have your cardwhite image so it wont be look like that one that you posted but just put the image in the linear layout background and it will look like the same as the one you posted.
<?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="wrap_content"
android:layout_margin="5dp"
android:background="#layout/cardwhite"
android:orientation="horizontal" >
<View
android:id="#id/viewlist"
android:layout_width="5dp"
android:layout_height="match_parent"
android:background="#52BD4F" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/first"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:fontFamily="sans-serif-light"
android:text="Customer 1"
android:textSize="15dp" />
<TextView
android:id="#+id/second"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:fontFamily="sans-serif-light"
android:text="Meeting"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
result:
Here is a small trick. Instead of giving height to the view use a TextView and give Height as MatchParant and set TextSize according to your need and set Background color to your TextView. Hope this helps you!
<TextView
android:id="#+id/col_status"
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_marginBottom="3dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="3dp"
android:background="#FFFFFF"
android:rotation="180"
android:textColor="#color/main_list_text"
android:textSize="12sp" />
This is my first try to create an android application.
I am trying to create a layout right now and am stuck allready.
Here is what I am trying to accomplish:
Jaarverbruik
2013 - 2014
Afrekendatum Peildatum
So, the word Afrekendatum should be aligned to the left, the word Peildatum should be aligned to the right of the screen.
This is my current 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="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<TextView
android:id="#+id/periode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="20sp"
android:text="#string/periode" />
<TextView
android:id="#+id/afrekendatum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/periode"
android:layout_alignParentLeft="true"
android:text="#string/afrekendatum" />
<TextView
android:id="#+id/peildatum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/periode"
android:layout_toRightOf="#id/afrekendatum"
android:layout_alignParentRight="true"
android:text="#string/peildatum" />
</RelativeLayout>
Sadly, the words are displayed directly behind each other.
What is the best way to fix this?
You don't need android:layout_toRightOf="#id/afrekendatum" because you have declared android:layout_alignParentRight="true". Remove it and it will work fine.
You should use something like this.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Try this...
You have to set TextView's gravity.
<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"
android:background="#2b579a"
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=".MainActivity1" >
<TextView
android:id="#+id/periode"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/periode"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:layout_margin="10dp"/>
<TextView
android:id="#+id/afrekendatum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="start"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:layout_below="#+id/periode"
android:text="#string/afrekendatum" />
<TextView
android:id="#+id/peildatum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/periode"
android:gravity="end"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:layout_toRightOf="#id/afrekendatum"
android:text="#string/peildatum" />
I also attached screenshot here Genius!
I have a problem with my xml for android.
I have this layout to use it in each line of a Listview (that works fine).
I want to put two lines (head and body) of text, and align Right of the first line I have to put two ImageView. (Also have first of all a hidden textView)
Something like this:
My problem is when I try to put both imageViews (with only one it shows fine, but with two don't show nothing).
this is my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/TvIdGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"
android:visibility="gone" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/TvName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ImgNewConvGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:src="#drawable/new_messages" />
<ImageView
android:id="#+id/ImgNewGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:src="#drawable/new_group" />
</LinearLayout>
<TextView
android:id="#+id/TvDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:textStyle="normal" />
</LinearLayout>
sorry for my english and thank you in advance!
If I am understanding correctly then I believe this should be close to what you are looking for:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/TvIdGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textSize="12sp"
android:textStyle="bold"
android:visibility="gone" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/TvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Test"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ImgNewConvGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="right"
android:src="#drawable/new_messages" />
<ImageView
android:id="#+id/ImgNewGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/ImgNewConvGroup"
android:gravity="right"
android:src="#drawable/new_group" />
</RelativeLayout>
<TextView
android:id="#+id/TvDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textSize="22sp"
android:textStyle="normal" />
</LinearLayout>
Try it out and let me know if that works for you, I changed the inner layout from LinearLayout to RelativeLayout and created what I believe you are looking for in relational locations.
Note: Be cautious of your TextView extending far enough to go behind the ImageViews, if that happens then it might be better to (set for the ImageViews):
android:layout_below="#+id/TvName"
on both and remove:
android:layout_centerVertical="true"
<TextView
android:id="#+id/TvIdGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="TV"
android:textSize="12sp"
android:textStyle="bold"
android:visibility="visible" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/TvName"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:text="TVName"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ImgNewConvGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="right"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/ImgNewGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="right"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<TextView
android:id="#+id/TvDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TVDescription"
android:textSize="22sp"
android:textStyle="normal" />
Take a look if is what are you looking for.
Is a lot of code just will write the structure
<LinearLayout android:orientation="vertical">
<LinearLayout android:orientation="horizontal">
<LinearLayout android:orientation="horizontal">
<TextView/>
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:gravity="right">
<ImageView/>
<ImageView/>
</LinearLayout>
</LinearLayout>
<LinearLayout android:orientation="vertical">
<TextView/>
</LinearLayout>
</LinearLayout>
In my application I am showing list of datas from database in a list view.For that listview i have 1 header with 4 text views arranged horizontally..But i want this to be arranged with some space exactly between and also it should fit into every screen. Please help me.Thanks in advance.By the following code it is arranging 1 after the other without space.
My code:
<?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="horizontal"
android:background="#ffffffff">
<TextView android:id="#+id/hdrdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"/>
<TextView android:id="#+id/hdrdateasc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="#+id/hdrdes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item"
/>
<TextView android:id="#+id/hdritemasc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="#+id/hdrprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
/>
<TextView android:id="#+id/hdrpriceasc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
/>
<TextView android:id="#+id/hdrtot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total"
/>
<TextView android:id="#+id/hdrtotasc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
/>
</LinearLayout>
You can use layout margin for spacing between view like
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
To fit them on the screen you can use layout_weight.Give every view weight 1 so all will be equal.You already use fill_parent for the width of your LinearLayout.
android:layout_weight="1" for every view
try this use android:layout_weight="1"in all TextView
<?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="horizontal"
android:background="#ffffffff">
<TextView android:id="#+id/hdrdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#ff00ff00"
android:text="Date"/>
<TextView android:id="#+id/hdrdateasc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="gffgfg"
android:textColor="#ffff0000"
android:layout_weight="1"
/>
<TextView android:id="#+id/hdrdes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#FF4500"
android:text="Item"
/>
<TextView android:id="#+id/hdritemasc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="gdgdfgsg"
android:textColor="#ff0000ff"
android:layout_weight="1"
/>
<TextView android:id="#+id/hdrprice"
android:layout_weight="1"
android:layout_width="wrap_content"
android:textColor="#ff00ff00"
android:layout_height="wrap_content"
android:text="Price"
/>
</LinearLayout>
Instead of wrap_content for widht you should use weight on your textview and weightsum on linear 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:orientation="horizontal"
android:background="#ffffffff"
android:weightSum="100.0">
<TextView android:id="#+id/hdrdate"
android:layout_width="0dp"
android:layout_weight="100/number of text views"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:text="Date"/>
....
</LinearLayout>
If you do not want to use exact values for your margins you should add some blank text views and set the weight smaller than the one of the ones in which you have text.
Here is the code,
<?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="horizontal"
android:background="#ffffffff">
<TextView android:id="#+id/hdrdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:layout_weight="1"
android:gravity="center_horizontal"/>
<TextView android:id="#+id/hdrdateasc"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:id="#+id/hdrdes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item"
android:layout_weight="1"
android:gravity="center_horizontal"/>
<TextView android:id="#+id/hdritemasc"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:id="#+id/hdrprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:layout_weight="1"
android:gravity="center_horizontal"/>
<TextView android:id="#+id/hdrpriceasc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000" />
<TextView android:id="#+id/hdrtot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total"
android:layout_weight="1"
android:gravity="center_horizontal"/>
<TextView android:id="#+id/hdrtotasc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000" />
</LinearLayout>
Being new to android I am still learning the intricacies of layouts. I am trying to create a simple bar on top of a map. For the most part this works fine.
My issue is that I want everything to be right aligned except for the Button which I want left aligned. I have tried quite a few combinations and am unable to get desired layout.
This is beginning to make me believe my structure as a whole is not correct. This seems like there should be an easy fix. What am I missing??
<LinearLayout
android:id="#+id/transparent_panel_hud"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right">
<Button
android:text="View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/arrow_down"
android:textSize="10sp"
android:drawablePadding="3dp"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingRight="15dp" >
<TextView
android:id="#+id/latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:text="#string/default_latitude"
android:textSize="18sp" />
<TextView
android:id="#+id/longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="#string/default_longitude"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingRight="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/speed"
android:textSize="18sp" />
<TextView
android:id="#+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/default_speed"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingRight="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/heading"
android:textSize="18sp" />
<TextView
android:id="#+id/heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/default_heading"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>![screenie][1]
Do the following changes to your XML layout, you will get the output as you mentioned. Try this.
Remove the line android:gravity="right" in LinearLayout with id=transparent_panel_hud
Keep your Button in a LinearLayout as below.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="left" >
<Button ... as you like />
</LinearLayout>
Keep your remaing 3 vertical LinearLayouts in a LinearLayout as below.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right" >
<LinearLayout vertical 1 ... as you like />
<LinearLayout vertical 2 ... as you like />
<LinearLayout vertical 3 ... as you like />
</LinearLayout>
I tested above changes to your code, its working. You too check it and let me know the result.
Try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/transparent_panel_hud"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:text="View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:layout_alignParentLeft="true"
android:drawablePadding="3dp"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/rightlayout"
android:layout_alignParentRight="true"
android:paddingRight="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="heading"
android:textSize="18sp" />
<TextView
android:id="#+id/heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="default_heading"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toLeftOf="#id/rightlayout"
android:orientation="vertical"
android:paddingRight="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="speed"
android:textSize="18sp" />
<TextView
android:id="#+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="default_speed"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>