tableLayout strechcolumns doesn't work - android

I have a TablLayout, it has 1 row and 2 columns.
The first column is a text, and I want it as big as possible, the second one is another table with 2 rows and 1 column:
<?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">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
>
<TableRow>
<TextView
android:id="#+id/parkingDataText"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
/>
<TableLayout>
<TableRow>
<ImageButton
android:id="#+id/buttonStar"
android:layout_marginLeft="10dip"
android:background="#null"
/>
</TableRow>
<TableRow>
<ImageButton
android:id="#+id/buttonRent"
android:layout_marginLeft="10dip"
android:background="#null"
/>
</TableRow>
</TableLayout>
</TableRow>
I thought I had to use strechColumns="1" and the first column occupied the space that the second one doesnt use, but it doesn't work.
Any idea?
Thank you in advance

Try below layout for your requirement :
<?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"
android:stretchColumns="2">
<TableRow>
<TextView
android:layout_column="1"
android:text="Save As..."
android:padding="3dip"
android:layout_width="200dp" />
<TableLayout
android:layout_column="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="2">
<TableRow>
<TextView
android:layout_column="1"
android:text="Textview column1"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="Textview column2"
android:padding="3dip" />
</TableRow>
</TableLayout>
</TableRow>
</TableLayout>

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.

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>

Android Layout Percentage/Proportion Resize

I have 3 layouts. First and third ones are RelativeLayout and the middle one is TableLayout. What I want is the TableLayout should lay over 80% of screen. And 10% for the others. How could I do this? android:layout_weight did not help me. Please could you put a code for this solution?
Ok here are some steps:
set to the relative and table layouts android:layout_width to 0dp
in the parent layout add android:weightSum to 10
in each of the 3 child layouts add android:layout_weight and set the first & third to the value of 1 and the middle table layout to 8.
Here is the code and screenshot:
<?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:weightSum="10" >
<RelativeLayout
android:id="#+id/leftPane"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:background="#336699"
android:layout_weight="1">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10% wide"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#00FFFF">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="row 1" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#33FFFF" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="row 2" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#66FFFF" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="row 3" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#99FFFF" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="row 4" />
</TableRow>
</TableLayout>
<RelativeLayout
android:id="#+id/rightPane"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:background="#336699"
android:layout_weight="1">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10% wide"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
</LinearLayout>

issue on Screen design with table layout under scroll layout.

I have seen an issue while designing dashboard screen,
I had one layout : say Linearlayout1 and having scroll layout: say scrollLayout1 as child of Linearlayout1, and havinf Table layout under this scroll layout,
i added table rows which contains buttons with drawables.
now the question is> I can see, table layout height is bit more than the scroll layout which is child of scroll layout. how child layout can have more height then parent layout. (I set table layout height as matchparent or fill parent).
If you are building a dashboard, then use the DashboardLayout from Google IO open source app.
That is the best way to do it. If you are planning to do something manually, it may not be possible to test on all the screen sizes, densities.
I used it in 3 of my projects, which just works.
Check this answer on stackoverflow.
Try This it may helps you
<?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"
>
<RelativeLayout
android:id="#+id/toplayout"
android:layout_width="fill_parent"
android:layout_height="50dip">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TopBar"/>
</RelativeLayout>
<ScrollView
android:id="#+id/scrolllayout"
android:layout_width="fill_parent"
android:layout_height="150dip"
android:padding="5dip"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:padding="5dip"
android:background="#android:color/darker_gray">
<TableRow>
<TextView
android:layout_column="1"
android:text="Open..."
android:textColor="#FFFFFF"
android:padding="3dip" />
<TextView
android:text="Ctrl-O"
android:gravity="right"
android:textColor="#FFFFFF"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="Save..."
android:textColor="#FFFFFF"
android:padding="3dip" />
<TextView
android:text="Ctrl-S"
android:gravity="right"
android:textColor="#FFFFFF"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="Save As..."
android:textColor="#FFFFFF"
android:padding="3dip" />
<TextView
android:text="Ctrl-Shift-S"
android:gravity="right"
android:textColor="#FFFFFF"
android:padding="3dip" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090" />
<TableRow>
<TextView
android:text="X"
android:textColor="#FFFFFF"
android:padding="3dip" />
<TextView
android:text="Import..."
android:textColor="#FFFFFF"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:text="X"
android:textColor="#FFFFFF"
android:padding="3dip" />
<TextView
android:text="Export..."
android:textColor="#FFFFFF"
android:padding="3dip" />
<TextView
android:text="Ctrl-E"
android:gravity="right"
android:textColor="#FFFFFF"
android:padding="3dip" />
</TableRow>
<View
android:layout_height="2dip"
android:textColor="#FFFFFF"
android:background="#FF909090" />
<TableRow>
<TextView
android:textColor="#FFFFFF"
android:layout_column="1"
android:text="Quit"
android:padding="3dip" />
</TableRow>
</TableLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>

Views/Widgets are not wrapping

I will just cut to the chase and paste all of my xml for a particular Activity below. The problem I'm having is that the widgets are not wrapping, and so much of the text is bleeding off the right edge of the screen.
As I'm using "wrap_content" for the width, I don't understand why this is happening.
<?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="wrap_content"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textViewSendLocWhenItChanges"
android:text="Send My Pterodactyl When It Changes"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<CheckBox
android:id="#+id/checkBoxSendToSelectedDuckbilledPlatypiWhenPterodactylChanges"
android:text="Send My Pterodactyl to Selected Duckbilled Platypi When It Changes" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<Button
android:id="#+id/buttonSendOnPterodactylChangedToSelected"
android:layout_weight="1"
android:text="Select Recipients From Contacts" />
<TextView android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<TextView
android:layout_span="1"
android:layout_weight="1"
android:text="Send Pterodactyl to selected Duckbilled Platypi from Contact List when my Pterodactyl changes by more than the following number of miles:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editTextMilesBeforeNotification"
android:layout_width="200px"
android:layout_span="1"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<TextView android:layout_height="10px" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<TextView android:layout_height="20px" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textViewBuildStringOfWhoReceivesChangeOfPterodactylUpdates"
android:layout_width="wrap_content"
android:text="Your Pterodactyl will be immediately sent to "
android:textAppearance="?android:attr/textAppearanceSmall" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<TextView android:layout_height="40px" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<Button
android:id="#+id/buttonNext"
android:layout_weight="1"
android:text="Save and Exit Keep In Touch Configuration" />
<TextView
android:layout_weight="1" />
</TableRow>
</TableLayout>
layout_width does not apply to TableRows. Use layout_span when you have a single column spanning two columns. Try using android:shrinkColumns. Hope it helps.

Categories

Resources