It is easy to place one TextView at right of another TextView but when width on base TextView more than screen size right TextView became not visible.
My XML layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/messages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:text="Messages" />
<TextView
android:id="#+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#drawable/bg_white_r30p0pl10"
android:drawableRight="#drawable/arrow_orange"
android:text="800" />
</LinearLayout>
How to make right TextView screen even if base TextView width is huge?
UPD:
In other words I need:
If first TextView is short:
|[ShotrTextView][TextView] |
If first TextView is long:
|[LooooooongTextVi...][TextView]|
The solution is TableLayout usage with shrinkColumns = 0
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="0" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/messages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:text="Messages" />
<TextView
android:id="#+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#drawable/bg_white_r30p0pl10"
android:drawableRight="#drawable/arrow_orange"
android:text="800" />
</TableRow>
</TableLayout>
Try this
<?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="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:inputType="text"
android:text="" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="0"
android:inputType="text"
android:text="12345" />
</LinearLayout>
Posting this as thinking line the only way to do the so...
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:singleLine="true"
android:layout_height="wrap_content"
android:text="Medium TextMedium TextMedium TextMedium Text"
android:maxWidth="280dp"
android:ellipsize="end"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="HHH"
/>
And create one dimension file like this and use it.
Check the answer in: Two TextViews side by side, only one to ellipsize?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView android:id="#+id/messages" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"
android:ellipsize="end" android:lines="1" android:text="Message" />
<TextView android:id="#+id/counter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp"
android:layout_weight="1" android:background="#drawable/bg_white_r30p0pl10" android:drawableRight="#drawable/arrow_orange" android:text="800" />
</LinearLayout>
Related
The screen of my application (https://i.stack.imgur.com/xFozp.png)
As seen in the image I have aligned textviews horizontally. When the product name is longer the name is displayed in 2 lines in the textview.
But when the number of lines in textview increases the starting lines of two textviews are not horizontally aligned.
I want the starting lines of textviews to be horizontally aligned.
Currently I am using LINEAR LAYOUT. Should I change the layout? Can anyone give the code to be written.
Thus even though 2 textviews are besides each other (as seen in the image) their starting( first line) should be in same horizontal line.
My code is as follows-
<?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:layout_margin="10dp"
android:background="#drawable/b22"
android:gravity="center|left"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="TextView"
android:textColor="#android:color/black"
android:textSize="15dp"
android:maxLines="3" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:text="TextView"
android:textColor="#android:color/black"
android:maxLines="3" />
</LinearLayout>
1. Remove attribute android:gravity="center|left" from LinearLayout.
2. Remove attribute android:layout_gravity="right|center" from textView2 and change its width as android:layout_width="match_parent".
Try this:
<?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="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="Product Name -"
android:textColor="#android:color/black"
android:textSize="15dp"
android:maxLines="3" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is Liberty Agile Pension Preserver Product"
android:textColor="#android:color/black"
android:maxLines="3" />
</LinearLayout>
OUTPUT:
For your design, its best to use a single RelativeLayout and put all of your TextViews inside it.
Here is an example:
<?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="10dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="Product Name -"
android:textColor="#android:color/black"
android:textSize="15dp"
android:maxLines="3" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/textView1"
android:layout_alignTop="#id/textView1"
android:text="This is Liberty Agile Pension Preserver Product"
android:textColor="#android:color/black"
android:maxLines="3" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView2"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:text="Number of Senarios Executed -"
android:textColor="#android:color/black"
android:textSize="15dp"
android:maxLines="3" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/textView3"
android:layout_alignTop="#id/textView3"
android:text="400"
android:textColor="#android:color/black"
android:maxLines="3" />
</RelativeLayout>
OUTPUT:
Hope this will help~
Consider using LinearLayout for group of two TextViews with weightSum. Give weight to both of them out of the sum. Below is an example
<LinearLayout
android:id="#+id/text_layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:weightSum="2"
android:background="#android:color/white">
<TextView
android:id="#+id/tvProductNameLabel"
android:layout_width="0dp"
android:layout_weight="0.6"
android:layout_height="wrap_content"
android:text="Product Name"
android:gravity="right"
android:textSize="14sp"
android:layout_marginRight="10dp"/>
<TextView
android:id="#+id/tvProductName"
android:layout_width="0dp"
android:layout_weight="1.4"
android:textSize="14sp"
android:textColor="#android:color/black"
android:layout_height="wrap_content"
android:text=""
android:layout_marginLeft="10dp"
android:layout_gravity="left"/>
</LinearLayout>
Searched and found many solutions but nothing seems to be working in my case.
I have 2 TextViews, side by side. This is what i am getting in preview.
and I want this
I have written following code, but its not giving me desired output.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<TextView
android:id="#+id/tvContactsHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="18sp"
android:paddingRight="10dp"
android:text="Heading "
android:textStyle="bold"
android:fontFamily="sans-serif-regular"
/>
<TextView
android:id="#+id/tvContactsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="18sp"
android:text="Text "
android:textStyle="normal"
android:fontFamily="sans-serif-regular"
/>
</LinearLayout>
</RelativeLayout>
If i use android:layout_gravity to left or right, it takes the whole text to left or right side.. I want to put both text in center, one starts from right corner and other starts from left corner.
Kindly guide me.
I have checked below XML file by myself ..
just put android:layout_weight="1" for both TextView and make android:layout_width="0dp" for both TextView..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="sans-serif-regular"
android:gravity="right"
android:paddingRight="10dp"
android:text="this code is working fine for me"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="sans-serif-regular"
android:gravity="left"
android:text="this is right side of the layout"
android:textSize="18sp"
android:textStyle="normal" />
</LinearLayout>
</RelativeLayout>
hope it will help u :)
You have to give match_parent width to LinearLayout.
Use this code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/tvContactsHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="18sp"
android:text="HeadingShort"
android:textStyle="bold"
android:paddingRight="10dp"
android:layout_weight="0.5"
android:fontFamily="sans-serif-regular"
/>
<TextView
android:id="#+id/tvContactsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textSize="18sp"
android:text="TextShort"
android:textStyle="normal"
android:layout_weight="0.5"
android:fontFamily="sans-serif-regular"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:layout_weight="1.0"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/tvContactsHeading2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="18sp"
android:text="HeadingLongggg"
android:textStyle="bold"
android:paddingRight="10dp"
android:layout_weight="0.5"
android:fontFamily="sans-serif-regular"
/>
<TextView
android:id="#+id/tvContactsText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textSize="18sp"
android:text="HeadingLoggg"
android:textStyle="normal"
android:layout_weight="0.5"
android:fontFamily="sans-serif-regular"
/>
</LinearLayout>
</RelativeLayout>
Your Output is
<TextView
android:id="#+id/tvContactsHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:paddingRight="10dp"
android:text="Heading "
android:textStyle="bold"
android:gravity="right|center_vertical|center_horizontal"
android:fontFamily="sans-serif-regular"
/>
<TextView
android:id="#+id/tvContactsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Text "
android:textStyle="normal"
android:gravity="center|center_vertical|center_horizontal"
android:fontFamily="sans-serif-regular"
/>
You can add android:layout_weight=1 for each text and then change the gravity as you like
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<TextView
android:id="#+id/tvContactsHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18sp"
android:paddingRight="10dp"
android:text="Heading "
android:textStyle="bold"
android:fontFamily="sans-serif-regular"
android:layout_weight="1"
/>
<TextView
android:id="#+id/tvContactsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18sp"
android:text="Text "
android:textStyle="normal"
android:fontFamily="sans-serif-regular"
android:layout_weight="1"
/>
</LinearLayout>
Also you can do that with relative layout which will be better
Set the layout_widthto match_parentand then apply your desired gravity.
The LinearLayoutdoes not allow you to place items on the right. So you have to set the TextViewto a full width, so you can apply the gravity for it's contents.
The other options is, that you could replace LinearLayoutwith FrameLayout.
The FrameLayoutallows absolute positioning, the LinearLayoutdoes not, which would not require to set the TextViewto a full width.
This is what I want to achieve:
main.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp" >
<TextView
android:id="#+id/tvNameContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="2dip"
android:layout_weight="0.29"
android:textColor="#FFF"
android:gravity="center_horizontal"
android:text="#string/fullname"
android:textStyle="bold" />
<TextView
android:id="#+id/tvDiagnosisContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_weight="0.57"
android:gravity="center_horizontal"
android:text="#string/diagnosis"
android:textColor="#color/white"
android:textStyle="bold" />
</LinearLayout>
custom_row.xml
<?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:orientation="vertical"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/fullname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="0.29"
android:text="text"
android:textColor="#color/black" />
<TextView
android:id="#+id/lname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.29"
android:text="text"
android:textColor="#color/black" />
<TextView
android:id="#+id/diagnosis"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.57"
android:text="#string/diagnosis"
android:padding="5dp"
android:textColor="#color/black" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/lastffupcontainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lastffup"
android:padding="5dp"
android:textColor="#color/black" />
<TextView
android:id="#+id/lastffup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lastffup"
android:padding="5dp"
android:textColor="#color/black" />
</LinearLayout>
</LinearLayout>
This is the result:
But I can't seem to make those spaces between the textviews. Any ideas?
Correct me if I'm wrong but it looks like the only issue you are having is having the "Diagnosis" TextView in the ListView spaced more to the right. For this I would change that LinearLayout to a RelativeLayout. Then you can give it the property android:layout_alignParentRight="true" and add in some android:marginRight="some dp" if needed.
You can use Android's new fancy GridLayout (http://developer.android.com/reference/android/widget/GridLayout.html or http://developer.android.com/reference/android/support/v7/widget/GridLayout.html) to get exactly what you're looking for.
Try and replace your LinearLayout tags with GridLayout instead and it just might work for you. (make sure you add the support library to your project if you need to support devices < api 14).
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.
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>