I was trying to change the alignment of text. This is what i have:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<TableRow>
<TextView
android:id="#+id/ctime"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:text="time" />
</TableRow>
<TableRow>
<TextView
android:id="#+id/cstatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="100"
android:text="status" />
</TableRow>
</TableLayout>
</LinearLayout>
Everything is left-aligned in the output even after setting android:layout_gravity="right".
This is a part of the layout, as I cant post the entire layout.
use this one
android:gravity="right"
Related
I am not able to align the image to textview.
What I want it to look like:
What it actually looks like:
Please ignore the background color, image size. The issue is related to aligning the image with the text view.
I have tried the following code:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableStart="#drawable/icon_checkin"
android:gravity="center"
android:text="#string/check_in"
android:drawablePadding="-20sp"
style="#style/roboto4F4F4Flight21"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="#drawable/icon_checkout"
android:text="#string/check_out"
style="#style/roboto4F4F4Flight21"
android:gravity="center"
/>
</LinearLayout>
Note: I have used android:drawablePadding="-20sp" but without success.
Also tried:
<TableLayout
android:id="#+id/linear_today_attendance"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns = "*"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="#drawable/icon_checkin"
android:gravity="center"
android:text="#string/check_in"
android:drawablePadding="-20sp"
style="#style/roboto4F4F4Flight21"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/icon_checkout"
android:text="#string/check_out"
style="#style/roboto4F4F4Flight21"
android:gravity="center"
/>
</TableRow>
</TableLayout>
Not the cleanest option, but it should work:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="#drawable/icon_checkin"
android:text="#string/check_in"
style="#style/roboto4F4F4Flight21" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="#drawable/icon_checkout"
android:text="#string/check_out"
style="#style/roboto4F4F4Flight21" />
</LinearLayout>
</LinearLayout>
Wrapping the TextView in a LinearLayout worked for me. Give it a shot.
// FYI, all columns are stretched using android:stretchColumns="*"
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_add_black_24dp"/>
</LinearLayout>
// and again same thing for the next item
<LinearLayout...>
<TextView.../>
</LinearLayout>
</TableRow>
I have a layout like this....
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Number of payrates (overtime etc)"
android:textSize="12sp" />
<Spinner
android:id="#+id/num_rate"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:textSize="12sp" />
</TableRow>
<TableRow>
<Button
android:id="#+id/cont"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Continue"
android:layout_gravity="bottom|right"/>
</TableRow>
</TableLayout>
Problem is that is still looks like this...
Meaning the button is conforming to the same amount of rows as above. Is there anyway (without switching layout types) to make it fill the entire row?
Also bonus points if you can point me towards how to move the button to the bottom of the screen.
// try this
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Number of payrates (overtime etc)"
android:textSize="12sp" />
<Spinner
android:id="#+id/num_rate"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="12sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom">
<Button
android:id="#+id/cont"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Continue"/>
</TableRow>
</TableLayout>
For row to fill entire row and to align your button to the bottom use Linear Layout instead of TableRow and give layout_gravity = "bottom".
Try the following data
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number of payrates (overtime etc)"
android:textSize="12sp" />
<Spinner
android:id="#+id/num_rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:textSize="12sp" />
</TableRow>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >
<Button
android:id="#+id/cont"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Continue" />
</LinearLayout>
</TableLayout>
Hope this works
http://i.stack.imgur.com/4Irb3.png
click above link for screen shot.
Ok so i'm having some problems editing my xml layout to get this list looking good. Basically i want each row of info to fill the whole list row, so that the white space you see in between each row isn't there. I have tried manipulating multiple different attributes in the row.xml and the main.xml but nothing has worked so far. Anyone have any advice? Thanks
row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:orientation="horizontal">
<TextView android:id="#+id/position"
android:textColor="#color/white"
android:background="#color/black"
android:layout_width="20dip"
android:textSize="14dip"
android:gravity="center"
android:layout_height="fill_parent"/>
<TextView android:id="#+id/team_name"
android:textColor="#000000"
android:background="#color/grey"
android:gravity="center"
android:layout_width="70dip"
android:textSize="14dip"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView android:id="#+id/games_played"
android:textColor="#000000"
android:background="#color/cyan"
android:layout_width="5dip"
android:textSize="14dip"
android:gravity="center"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView android:id="#+id/points"
android:textColor="#000000"
android:background="#color/turquoise"
android:layout_width="5dip"
android:textSize="14dip"
android:gravity="center"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="Team"
android:background="#color/red"
android:textColor="#color/white"
android:gravity="right"
android:layout_width="wrap_content" />
<TextView
android:text="Games Played"
android:background="#color/red"
android:textColor="#color/white"
android:gravity="center"
android:layout_width="wrap_content"
android:paddingLeft="22dip" />
<TextView
android:text="Points"
android:background="#color/red"
android:textColor="#color/white"
android:gravity="left"
android:layout_width="wrap_content"
android:paddingRight="18dip"/>
</TableRow>
<TableRow >
<ListView
android:background="#color/white"
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
Did you set android:minHeight prop as well as android:layout_height of LinearLayout? this will fixes the row height.
i figured it out, i had to remove the padding attributes in the linearlayout, can't believe i didn't figure it out before!
I'm trying to create an android screen that has a TableLayout anchored to the top, then a scrollview to fill middle, and TableLayout anchored to the bottom. I used a RelativeLayout with alignParentTop/alignParentBottom and the bottom TableLayout shows up, but the top one disappears.
Is it possible to have separate sections anchored at both top and bottom with a scrollable region filling the middle? Imagine a button bar on top and bottom with scrollable items in the middle. Here is my layout that was close but doesn't quite work. I also tried with a TableLayout and 3 rows with the middle one set to fill_parent and ScrollView, but couldn't get that to work either.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout01"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:id="#+id/CategoryTable01"
android:stretchColumns="*"
android:background="#000000"
android:layout_height="80px"
android:layout_alignParentTop="true"
android:layout_width="fill_parent">
<TableRow
android:id="#+id/tr01"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:padding="10px"
android:layout_gravity="center_vertical|center_horizontal">
<TextView android:text="TOP1" android:textColor="#0000FF" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
<TextView android:text="TOP2" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
</TableRow>
</TableLayout>
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout02"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:id="#+id/TableLayout01"
android:stretchColumns="*"
android:background="#drawable/gradient"
android:layout_height="wrap_content"
android:paddingLeft="20px"
android:layout_width="fill_parent">
<TableRow
android:id="#+id/TableRow01"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
<TextView android:textColor="#FFFFFF"
android:textStyle="bold"
android:textSize="12dip"
android:text="Sample Line 1"></TextView>
</TableRow>
<TableRow
android:id="#+id/TableRow02"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
<TextView android:textColor="#FFFFFF"
android:textSize="11dip"
android:text="Sample Line 2"></TextView>
</TableRow>
<TableRow
android:id="#+id/TableRow03"
android:layout_height="600px"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
<TextView android:textColor="#FFFF00"
android:textSize="11dip"
android:text="Sample Line 3"></TextView>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
<TableLayout
android:id="#+id/CategoryTable02"
android:stretchColumns="*"
android:background="#000000"
android:layout_height="80px"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent">
<TableRow
android:id="#+id/tr02"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:padding="10px"
android:layout_gravity="center_vertical|center_horizontal">
<TextView android:text="ONE" android:textColor="#0000FF" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
<TextView android:text="TWO" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
<TextView android:text="THREE" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
<TextView android:text="FOUR" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
</TableRow>
</TableLayout>
</RelativeLayout>
Thanks for any suggestions or help.
Michael
It is indeed possible. This is how I've got it working in one of my apps (I've cut out a bunch of irrelevant stuff like ids):
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--this is the action bar at the top of the screen)-->
<fragment
android:layout_width="match_parent"
android:layout_height="40dip" />
<!-- This is the list view in the middle -->
<ListView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dip">
</ListView>
<!-- This is a bunch of buttons at the bottom -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dip"
android:gravity="bottom">
</RelativeLayout>
</LinearLayout>
The key is to set your middle listview to height 0dip and let layout_weight take over - layout_weight is kind of comparable to percentage widths/heights in HTML - if you have 4 different elements with weight 0.25, they'll each take up a quarter of the screen. So weight 1.0 takes up whatever it can.
Here's my issue I have a login and want to line up the EditText fields. See the mockup picture attached .
I have tried a few ways and cannot figure out how to make the fields lineup.
I really hate layouts in Android I spend more time just messing with things to line up right. Wish they would just scrap it and use something more intuitive, as its more like using tables in HTML. So in advance thanks for your help and cheers!
You could probably play around with RelativeLayout and get just what you want.
Here's an approximation with TableLayout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_marginTop="40dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="10dip"
android:text="UserID:" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="USER ID" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="10dip"
android:text="Password:" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="PASSWORD" />
</TableRow>
</TableLayout>
<LinearLayout
android:layout_marginTop="50dip"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3"
android:gravity="center">
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="LOGIN" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="REGISTER" />
</LinearLayout>
</LinearLayout>
See if this works for you. It doesnt center quite perfectly but it does align well across multiple screen sizes.
<?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:background="#FFFF0000">
<LinearLayout android:id="#+id/top_row"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_marginTop="25dip">
<LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="fill_parent">
<TextView android:layout_height="wrap_content" android:text="User Id" android:gravity="right" android:layout_marginRight="10dip" android:layout_width="fill_parent" android:layout_weight="2" android:textColor="#FF000000"></TextView>
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:ems="10" android:layout_weight="1"></EditText>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="fill_parent">
<TextView android:layout_height="wrap_content" android:text="Password" android:gravity="right" android:layout_marginRight="10dip" android:layout_width="fill_parent" android:layout_weight="2" android:textColor="#FF000000"></TextView>
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:ems="10" android:layout_weight="1"></EditText>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_width="wrap_content" android:layout_below="#+id/top_row" android:layout_centerHorizontal="true" android:layout_marginTop="20dip">
<Button android:layout_width="wrap_content" android:text="LOGIN" android:layout_height="wrap_content" android:layout_marginRight="10dip"></Button>
<Button android:text="REGISTER" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="10dip"></Button>
</LinearLayout>
</RelativeLayout>
Here's what it looks like in my IDE...
You can do this quick and dirty using TableLayout, just add a TableRow with a TextView and a EditText for the userid and repeat the same for the password.
See http://developer.android.com/resources/tutorials/views/hello-tablelayout.html