Adding headers above ListView in XML - java

I'm trying to add 3 headers going from left to right above a ListView. I'm trying to add TextViews to achieve this. I've attached a picture to better demonstrate. Picture
My ListView works as i want it to by itself but I can't seem to get the textViews to align as i want them to.
activity_visualise.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/latitudeHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/listView"
android:layout_alignLeft="#+id/longitudeHeader"
android:text="#string/latitudeHeader"/>
<TextView
android:id="#+id/longitudeHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/listView"
android:text="#string/longitudeHeader"/>
<TextView
android:id="#+id/syncHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/listView"
android:layout_alignRight="#+id/longitudeHeader"
android:text="#string/syncHeader"/>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>
activity_visualise_row.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_visualise_database"
android:layout_width="match_parent"
android:layout_height="match_parent"
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="org.softshack.VisualiseDatabaseActivity">
<TextView
android:id="#+id/dbLatitude"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1" />
<TextView
android:id="#+id/dbLongitude"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1" />
<TextView
android:id="#+id/dbReportTime"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1" />
<TextView
android:id="#+id/dbSyncStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"/>
</LinearLayout>

Didn't see the rest of your code but you can try and put the headers as the first row on your ListView instead of the TextViews..

Couldn't align it properly in XML so I added the headers into the listview as strings. Had issues with them randomly repeating and this fixed it List view items changes position when scrolling android?

As the parent of your header view use a linear layout (horizontal) and apply a weightSum of 1 on it. then add 4 textviews as the childs of the linear layout and apply a layout weight of 0,25 on every one of them. do the same for the single list row view and you will get the result that you want.
UPDATED ANSWER:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView" android:layout_weight="0.25"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView2" android:layout_weight="0.25"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView3" android:layout_weight="0.25"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView4" android:layout_weight="0.25"/>
</LinearLayout>
P.S. you can use a gridview widget to get the same result.

Related

How to make Dynamic one row 7 columns that has horizontal Scroll

So i have been working on my android project and the layout has gotten me and I cannot figure out what is the best to do something like this.
Currently my XML looks like this.
What i am trying to do is have 7 columns with one row that is filled with textviews. I was looking at Grid views but it seems like the entire point of the grid is to scroll with more than one row. How do I achieve this layout?
<android.support.constraint.ConstraintLayout
android:id="#+id/ConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/foodmenuexample"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView11"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="123456789123456789123456789123456789123456789123456789123456789" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<TextView
android:id="#+id/textView12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
The answer is... it depends. For simplicity, you can use a GridLayout, which if you have all your data within the view, this would work well.
However if you want the data to load from a database, or if there is an indeterminate amount of columns, then a gridview is your best bet inside a horizontal scrollview. You can just set the number of rows to 1, and the number of columns programmatically.
Example of that:
GridView gridView = (GridView) findViewById(R.id.gridview);
gridView.setNumColumns(numOfColumns);
Gridviews are more complicated because you will have to use an adapter, which you can learn about here:
https://developer.android.com/guide/topics/ui/layout/gridview.html
However, if you are looking for static simplicity, here is what you could do:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent">
<GridLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:rowCount="1"
android:columnCount="7">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Lots of text on this one" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Some text on this one" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Textview3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Textview4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Textview5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Textview6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Textview7" />
</GridLayout>
</HorizontalScrollView>
</android.support.constraint.ConstraintLayout>

TabWidget custom tabs - unwanted extra margin and text aligment issues

I'm using TabWidget to get tabbed navigation. Each tab tile has icon and text below it. As content of my tab I currently have cardview list.
So, tab button layout:
<LinearLayout android:id="#+id/tabsLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/tab_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="bottom|center"/>
<TextView android:id="#+id/title"
style="#android:style/TextAppearance.Holo.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textColor="#000000"
android:text="test"
android:visibility="visible"
android:focusableInTouchMode="false"
android:layout_gravity="center"
android:textIsSelectable="true" android:textSize="13sp"
android:textAlignment="center"
android:gravity="center_horizontal"/>
</LinearLayout>
My activity where tab widget is used:
<?xml version="1.0" encoding="utf-8"?>
<TabHost
android:id="#android:id/tabhost"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="#+id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" android:background="#84dadada"/>
</LinearLayout>
</TabHost>
FrameLayout is for replacing tab content with fragments when user switch between tabs. It works, but there are some problems though. This is how it looks like:
As you can see - first problem is icon alignment. If text is wrapped as multiline (large font and small screen), icon is not aligned with the rest ones that have one line label. How to get all icons properly aligned?
Second - there is white extra space just above my tab control - why? How to disable it?
Any ideas?
[edit]
My CardView is defined as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="3dp"
>
<android.support.v7.widget.CardView android:id="#+id/card_view"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:background="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="0dp"
card_view:cardElevation="dp" android:clickable="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/card_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:padding="6dp"
android:src="#drawable/ic_launcher"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:orientation="vertical"
android:padding="4dp">
<TextView
android:id="#+id/card_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold"/>
<TextView
android:id="#+id/card_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
<ImageView
android:id="#+id/arrow"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:padding="6dp"
android:src="#drawable/arrow"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
So it seems there is extra margin around cardview - top, bottom, left and right. How to disable it?
For the space issue have a look here, it may be a duplicate answer.
For the icon-alignment, have a look here, it shows how to keep your text on a single-line and use ellipsis to truncate it if your device doesn't have room to show it entirely. It may not be your perfect solution, but it's a good hint.

Android app relative layout with 2-3 elements and a bottom button

I want to design an android activity with a relative layout. There should be 3 (or later 4) elements in a vertical line among each other. I've tried it, but the textview is hidden behind the listview.
What's wrong with the code, how should I change it and how should it look, if I want to insert a fourth element between the text and listview or the listview and button ... like a image.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:paddingBottom="10dp"
android:layout_above="#+id/listview"
android:text="#string/info" />
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button"
android:layout_marginBottom="10dp" />
<ImageButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="start"
android:src="#drawable/button1" />
</RelativeLayout>
Try changing ReltiveLayout to LinearLayoutor put LinearLayout outside your RelativeLayout, whith orientation="vertical" an put the TextView outside RelativeLayout. Something like this:
<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/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/info" />
<RelativeLayout
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button"
android:layout_marginBottom="10dp" />
<ImageButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="start"
android:src="#drawable/button1" />
</RelativeLayout>
</LinearLayout>

Unable To Center Objects Within Two Relative Layouts

I'm attempting to split the UI for my horizontal layout into two halves each with it's own realative layout so I am able to center text and graphics within the two left and right halves of the screen. The problem is when I attmept to do so - the go button still ends up in the middle of the screen instead of centered on the right hand of the screen.
(If I can figure out how to center correctly I'm sure I'll be able to apply the same technique to the other elements to achieve the result I desire.
SOURCE:
<?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:layout_marginBottom="8sp"
android:layout_marginLeft="8sp"
android:layout_marginRight="8sp"
android:layout_marginTop="8sp"
android:background="#drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/emblem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="24dp"
android:gravity="center"
android:scaleType="fitStart"
android:src="#drawable/apn_app_logo" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/start2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" >
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/go_button"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/start_text2"
android:textColor="#000000"
android:textSize="18sp" />
<Button
android:id="#+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/apn_app_go_button" />
</RelativeLayout>
</RelativeLayout>
EDIT: (in response to Kuba's answer)
<?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="horizontal"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/background"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/emblem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="24dp"
android:gravity="center"
android:scaleType="fitStart"
android:src="#drawable/apn_app_logo" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/background"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="#+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/apn_app_go_button"
android:gravity="center_horizontal" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/start_text2"
android:textColor="#000000"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
Instead of Relative layout, I would recommend using LinearLayout.
<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="horizontal"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:background="#00dd00"
android:gravity="center"
>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:background="#dd0000"
android:gravity="center_horizontal"
>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
In the inner LinearLayout you can either use android:gravity="center" to have its children centered vertically and horizontally. Or use use android:gravity="center_horizontal" to center in only horizontal way.
EDIT: Added the textview, which was discussed in the comments.
To have the textView appear underneath the button, you must change the orientation of the LinearLayout from horizontal to vertical. Please see the developer site .
The inner LinearLayout thus looks like this.
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:background="#dd0000"
android:gravity="center"
>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text here"
/>
</LinearLayout>
How can I use android:layout_below="#+id/go_button" in a linear layout?
You can't. These relationships only work in relative layout where you place views in relation to each other or the parent view. In linear layout items are stacked either vertically or horizontally.
Set android:gravity="center" in
<Button
android:id="#+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/apn_app_go_button" />
Maybe its work.

How can I align this layout correctly?

I have two textviews. I want one of them to be left aligned and the other to be right aligned. Pretty much so that it looks like a 2 column table.
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="#+id/profileLayout" android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:id="#+id/experience" android:orientation="horizontal">
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/experienceLabel" android:textStyle="bold" android:layout_weight="0" android:text="Experience"></TextView>
<LinearLayout android:id="#+id/linearLayout4" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1"></LinearLayout>
<TextView android:text="TextView" android:layout_height="wrap_content" android:id="#+id/experienceTextView" android:layout_gravity="right" android:layout_weight="0" android:layout_width="wrap_content"></TextView>
</LinearLayout>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal">
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1"/>
<TextView android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="wrap_content"/>
</LinearLayout>
Set the weight of the first one to 1 so it will eat up all of the extra space. Set the 2nd oen to wrap content, so it only takes up as much space as it needs.
But why do you have an extra LinearLayout around them? If you have nested LinearLayouts, you should probably be using a RelativeLayout instead.
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/experienceLabel" android:textStyle="bold" android:layout_weight="1" android:text="Experience"></TextView>
<TextView android:text="TextView" android:layout_height="wrap_content" android:id="#+id/experienceTextView" android:layout_weight="1" android:layout_width="wrap_content"></TextView>
</LinearLayout>
Use Relative Layout. About Relative Layout Link Example link
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/experienceLabel"
android:textStyle="bold" android:layout_weight="0" android:text="Experience"
android:layout_alignParentLeft="true"/>
<TextView android:text="TextView" android:layout_height="wrap_content"
android:id="#+id/experienceTextView" android:layout_gravity="right"
android:layout_weight="0" android:layout_width="wrap_content"
android:layout_alignParentRight="true" />
Benefit of using RelativeLayout: it reduces your number of layout. Which will optimize your ui too.
I'm not entirely sure of the exactly layout you want, but you can 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:id="#+id/profileLayout"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:id="#+id/experience"
android:orientation="horizontal">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/experienceLabel"
android:textStyle="bold"
android:layout_weight="1"
android:text="Experience"/>
<TextView
android:text="TextView"
android:layout_height="wrap_content"
android:id="#+id/experienceTextView"
android:gravity="right"
android:layout_weight="1"
android:layout_width="wrap_content"/>
</LinearLayout>
</LinearLayout>
You were using layout_gravity rather than gravity also. layout_gravity tells the parent how you want to be laid out, gravity tells content how to be laid out.
Notice how I have a weightSum in the parent layout to 2 and then set the two children to a weight of 1 each. I also set the parent to fill_parent
You had and extra layout in there too - if you want spacing, set a margin on the second textview or use a view (a simpler object than a LinearLayout)

Categories