How to align Text to right in Text Views - android

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.

Related

How to place textviews with large text on left and right?

i am using two textviews to display total balance for this i am using two textviews the first textview has a large text string and second one will have amount that is also a large number. the problem is that when content loads the text of first string is under text of second string. how to fix this?
here is my code any help will be appreciated
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rlaout_balance_list_item"
android:orientation="horizontal"
android:weightSum="10"
>
<TextView
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:text="type"
android:id="#+id/txt_balance_list_footer_item_type"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textColor="#000000"
android:textSize="#dimen/balance_list_item"
android:layout_weight="8"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/txt_balance_list_footer_item_value"
android:text="0.0"
android:paddingLeft="10dp"
android:textColor="#color/balance_list_cash"
android:textStyle="bold"
android:textSize="#dimen/balance_list_item"
android:layout_weight="2"/>
</LinearLayout>
Use Relative layout instead of linear
<RelativeLayout
android:id="#+id/rlaout_balance_list_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txt_balance_list_footer_item_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingLeft="10dp"
android:text="0.0"
android:textColor="#color/balance_list_cash"
android:textSize="#dimen/balance_list_item"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_balance_list_footer_item_type"
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/txt_balance_list_footer_item_value"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textColor="#000000"
android:textSize="#dimen/balance_list_item"
android:textStyle="bold" />
</RelativeLayout>
<LinearLayout
android:id="#+id/rlaout_balance_list_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/txt_balance_list_footer_item_type"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="type"
android:textColor="#000000"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_balance_list_footer_item_value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:paddingLeft="10dp"
android:text="0.0"
android:textSize="40dp"
android:textStyle="bold" />
</LinearLayout>
You will never get the result as you want if you use a layout like this. Please change the android:orientation="horizontal" to android:orientation="vertical"
Otherwise try something like 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="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textView8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:gravity="start"
android:text="TextViecxvvvvvvvvvvvvvvvcvxbcxv
bcxvbcxvvvvvvvvvvvbcxvbcxvbcxvbcxvbcvbcxvbcxvbcxvbcxvbcxvbnbm,vvvvvvvvvvvvvvvvvvvvvvvvvvvcbbbbbbbbbbbbbbbbbbbbbbbvw" />
<TextView
android:id="#+id/textView9"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="2"
android:text="cvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxvxb" />

Align Image View to top of the screen in a linear layout

I'm trying to align an image image with space at top of pictureat the top of a Linear Layout in android studio.I have a space as you can see on the picture. I would like to get rid of that space. Tried few things without success!!! Anyone has a clue how to do it??? Thanks
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.bourgeois.michel.relativesinglescreenapp.MainActivity">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/topLinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/toppicture"
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="#drawable/danielarias" />
<TextView
android:id="#+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:textColor="#ff6600"
android:textStyle="bold"
android:paddingLeft="10dp"
android:text="Phone"/>
<TextView
android:id="#+id/number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textColor="#000"
android:textStyle="normal"
android:text="424-278-8938"/>
<View
android:id="#+id/line"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="10dp"
android:background="#ff6600"/>
</LinearLayout>
<LinearLayout mlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/text"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:textColor="#000"
android:textStyle="bold"
android:text="Address: 5867 W 3rd St, Los Angeles, CA 90036"
/>
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button"
android:fontFamily="sans-serif-condensed"
android:paddingBottom="1dp"
android:textAlignment="center"
android:textColor="#000"
android:textSize="16sp"
android:text="Learn How To Dance Milonguero Tango Style!"/>
<TextView
android:id="#+id/thursday"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:paddingBottom="5dp"
android:textAlignment="center"
android:textColor="#000"
android:textSize="16sp"
android:text="Every Thursday Night"/>
<TextView
android:id="#+id/hour"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:paddingBottom="5dp"
android:textAlignment="center"
android:textColor="#000"
android:textSize="16sp"
android:text=" 8:30pm to 9:30pm"/>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15dp"
android:text="Join Us" />
Use your ImageView like :
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="fitXY"/>
Problem can be about your image sources width and height. There is no marginTop in your xml. Give a try like adding android:scaleType="fitXY" to your ImageView.
try adding
android:adjustViewBounds="true"
in ImageView parameters,adding scaleType="fitXY" will stretch the image so avoid it.

Android GUI: Layout manager

I'm learning about Layout managers to improve my app design. For the most part it worked out ok. The only thing I want is my buttons to be positioned a little higher.I can achieve this by removing the 3 buttons from the layout manager but by doing this I have issues on lower res devices. (The buttons will position themselves over the EditText fields or position themselves over my ad at the bottom). I've tried some things I found online but I only ended up ruining the layout.
Here is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/textviewLayoutLeft"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tvPpl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp"
android:text="Price Per Liter"
android:textStyle="bold" />
<TextView
android:id="#+id/tvAvgConsumption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:text="avg(l/100km)"
android:textStyle="bold" />
<TextView
android:id="#+id/tvDistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Distance (km)"
android:textStyle="bold" />
<TextView
android:id="#+id/tvAmountOfPersons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:text="# Persons"
android:textStyle="bold" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp"
android:text="Price Per Person"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/textfieldLayoutRight"
android:layout_width="166dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/textPrijsPerLiter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/textVerbruik"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/textAfstand"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/textAantalPersonen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:imeOptions="actionGo"
android:inputType="numberDecimal" />
<TextView
android:id="#+id/textViewPPP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="20dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffff000f"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<Button
android:id="#+id/btnBereken"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Calculate"
android:textStyle="bold" />
<Button
android:id="#+id/btnReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset all textfields"
android:textStyle="bold" />
<Button
android:id="#+id/btnLoad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load latest results"
android:textStyle="bold" />
</LinearLayout>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="MY_ID" />
</LinearLayout>
</RelativeLayout>
You can:
Give up second linear layout and move button layout and ad layouts to main layout. Stick ad layout to bottom and declare it BEFORE button layout. Set buttons adjustments to layout_below="textfieldlayout" and layout_above="ad" instead of layout_alignParentBottom="true".
Consider using linear layout with weightSum. Every parent layout should have weightSum=100, every child will respectively have % of space. From my point of view this way would be the best, because views will position equally for merely all devices and even layout tree depth will remain the same. You'll only have to change the parent layout to LinearLayout and set weights.

How to disable or block TextView to not narrowed other elements of the Layout

I have problem with my TextView, when something is written in it. It narrows the right layout.
like here:
1 Without something is written: http://i.stack.imgur.com/zItJw.jpg
2.Without something is written in: http://i.stack.imgur.com/b5Nb4.jpg
My Layout Code:
1st bar:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/czas_punkty_bez_napisu"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/dzialanie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="25sp"
android:text="X razy Y" />
<TextView
android:id="#+id/equal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="25sp"
android:text="=" />
<TextView
android:id="#+id/tylemabyc"
android:textSize="25sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
</LinearLayout>
2nd bar
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="#drawable/czas_punkty_bez_napisu"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/czas"
android:textSize="25sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
3rd bar:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="#drawable/czas_punkty_bez_napisu"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/wynik"
android:textSize="25sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
How to block 1st TextView to not narrows others ?
You can use layout_weight property to tell android how much space each textView takes on the screen. If you want all of them to have the same space you can add the layout_weight of 1 for all of them.
You will also need to readjust your layout_width too. You will have to trade off for the layout_heght. For example if i want 4 textviews in a horizontal line holding equal space "Horizontally" i would do something like 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="match_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="This is verrry long text" />
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="maybe not" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="let us see" />
<TextView
android:id="#+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ok" />

Align textviews in linearlayout

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).

Categories

Resources