In TableLayout TableRow align button right? - android

I am trying to align a button to the right of a TableRow. Inside the TableRow I have two textviews and a button. The middle textview is hidden when the button is displayed. This is done inside my adapter by setting the textview visibility to gone.
I am not sure what the best approach is to aligning the button to the right when it is displayed.
Here is my Layout file:
<?xml version="1.0" encoding="UTF-8" ?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget28"
android:stretchColumns="1"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingLeft="10sp"
android:descendantFocusability="blocksDescendants"
>
<TableRow>
<TextView
android:id="#+id/textTopLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium">
</TextView>
<TextView
android:id="#+id/textTopRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium">
</TextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/textBottomLeft"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
<TextView
android:id="#+id/textBottomRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
<Button
android:id="#+id/btnSessionResume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Resume"
android:visibility="invisible"
android:layout_marginRight="20px"
android:layout_alignParentRight="true">
</Button>
</TableRow>
</TableLayout>
The button is in the bottom TableRow.
Here is a screenshot of what the layout currently looks like:

//use android:layout_span and remove your right margin for you button
<?xml version="1.0" encoding="UTF-8" ?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget28"
android:stretchColumns="1"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingLeft="10sp"
android:descendantFocusability="blocksDescendants"
>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_span="2">
<TextView
android:id="#+id/textTopLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium">
</TextView>
<TextView
android:id="#+id/textTopRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium">
</TextView>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textBottomLeft"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
<TextView
android:id="#+id/textBottomRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
<Button
android:id="#+id/btnSessionResume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Resume"
android:visibility="invisible"
android:layout_marginRight="5dp"
android:layout_alignParentRight="true">
</Button>
</TableRow>
</TableLayout>

Perhaps you can have a relative layout in the table row and then use android:layout_alignParentLeft on the TextViews and android:layout_alignParentRight on the button.

Related

How to add scroll view in tablelayout? so is show all textview

I finally solve me last post issue by weight attribute but one problem is come when I give multi line text last Textview not show which in this url http://imgur.com/ApL5c
How do I add scroll view in my code?
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:weightSum="11"
android:layout_margin="5dp">
<TableRow>
<TextView
style="#style/StyleLabel"
android:text="#string/name_lbl"/>
<TextView
android:id="#+id/nameText"
android:layout_weight="2"
style="#style/StyleText"/>
</TableRow>
<TableRow>
<TextView
style="#style/StyleLabel"
android:text="#string/cap_lbl"/>
<TextView
android:id="#+id/capText"
android:layout_weight="2"
style="#style/StyleText"/>
</TableRow>
<TableRow>
<TextView
style="#style/StyleLabel"
android:text="#string/code_lbl"/>
<TextView
android:id="#+id/codeText"
android:layout_weight="1"
style="#style/StyleText"/>
</TableRow>
<TableRow>
<TextView
style="#style/StyleLabel"
android:text="#string/DoneDate_lbl"/>
<TextView
android:id="#+id/Location_lbl"
android:layout_weight="1"
style="#style/StyleText"/>
</TableRow>
<TableRow>
<TextView
style="#style/StyleLabel"
android:text="#string/Notes_lbl"/>
<TextView
android:id="#+id/Notes_lbl"
android:layout_weight="4"
style="#style/StyleText"
/>
</TableRow>
<TableRow>
<TextView
style="#style/StyleLabel"
android:text="#string/person_lbl"/>
<TextView
android:id="#+id/Person_lbl"
android:layout_weight="1"
style="#style/StyleText"/>
</TableRow>
Simply surround it in a scrollview like the following--
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:weightSum="11"
android:layout_margin="5dp">
<TableRow>
<TextView
android:text="textview1"/>
<TextView
android:id="#+id/nameText"
android:text="tewgoijirtgujerioug"
android:lines="15" //You can add lines to make your textview occupy the no of lines you want instead of weight.
android:layout_weight="2"
/>
</TableRow>
............
.............
</TableLayout>
</ScrollView>
Hope this helps.

LinearLayout doesn't fill tablerow even width fill_parent is called

I have a linearLayout inside a tableRow, this linearLayout contains a chart that i would like to display for my app.
I read some thread saying that the child of the tableRow not need to specify its width and height, so I did it, but the chart is not displayed. If I specify the linearLayout to be width=fill_parent and height=200dp, then the linearlyLayout is only fill 1/3 of the tableRow.
<?xml version="1.0" encoding="UTF-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Record"
android:textSize="18dp"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="Name:"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:ems="10"
android:singleLine="true" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="Date:"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="#+id/editRecordDate"
android:layout_width="0dp"
android:layout_weight="0.7"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tableRow9"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/soundaomplitude_graphViewLinearLayout"
android:paddingTop="4dip" > //if I specify nothing then nothing is displayed, if I set width = fill_parent and height = 200dp, then only 1/3 of the space is occupied
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow10"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/saveEditRecord"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="Save" />
<Button
android:id="#+id/deleteEditRecord"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="Delete" />
<Button
android:id="#+id/cancelEditRecord"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight=".3"
android:text="Cancel" />
</TableRow>
</TableLayout>
</ScrollView>
I found out just set the weight = 1(or any number) for the linearLayout
<LinearLayout
android:id="#+id/soundaomplitude_graphViewLinearLayout"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_weight="1"
android:paddingTop="4dip" />
It seems that a TableRow acts as a LinearLayout, hence nesting one right inside a TableRow seems redundant. In Eclipse also, it says, that it is "useless". Therefore, you can just include your view (any view) directly inside the TableRow, instead of the LinearLayout. If it is not showing, then, there is probably some other problems.
Read again on how TableLayout manages its content. Specifically note that it disregards the layout_width of child views.

How to right align text

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"

EditText in a tableRow how to fix 100%

I have a linearlayout with a table and a button, the table has EditText and TextView, my problem is with EditText, which is too small
<LinearLayout
android:orientation="vertical"
android:layout_width="300dip"
android:layout_height="350dip"
android:background="#drawable/background_resto"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity ="center"
>
<TextView
android:id="#+id/nameRegister"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="Nombre"
android:layout_marginLeft="10dip"
/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity ="center"
>
<EditText
android:id="#+id/registerName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
/>
</TableRow>
</TableLayout>
<Button
android:id="#+id/butRegister"
android:layout_height="35dip"
android:layout_width="wrap_content"
android:text="Enviar"
/>
</LinearLayout>
</LinearLayout>
I would like the EditText fix the 300dip that the first linearLayout, but I don't get it, what should I do?
Try this, add to TableLayout stretchColumns param
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:stretchColumns="1"
>

TableRow with image and 2 TextView

I`m having problems for do something like this: http://imageshack.us/photo/my-images/824/examplehm.png/
My xml code shows 3 columns in the row but i want 2 columns and the second column must be divided in two horizontal parts.
My .xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
<TableRow>
<ImageView android:id="#+id/imagen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="2dip"
android:paddingRight="5dip" />
<TextView android:id="#+id/cabecera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="12px" />
<TextView android:id="#+id/descripcion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="normal"
android:textSize="10px" />
</TableRow>
</TableLayout>
Someone could help me?
Thanks.
Put LinearLayout by the image and then put in it two TextViews , or use RelativeLayout for entire row.
Here is example of the first solution:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow>
<ImageView android:id="#+id/imagen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="2dip"
android:paddingRight="5dip" android:src="#drawable/ic_launcher"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical" android:gravity="center_vertical">
<TextView android:id="#+id/cabecera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="12px"
android:text="TextView"/>
<TextView android:id="#+id/descripcion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="normal"
android:textSize="10px"
android:text="TextView" />
</LinearLayout>
</TableRow>

Categories

Resources