I want this special table layout:
In my current layout the cells that are shorter are at the same size like the cells with the long text:
How do have to do it?
It should look like the first picture.
There may be better ways of doing this, I actually haven't used TableLayout before, but the XML below gives the basic layout that you asked for:
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="4"
android:layout_weight="1"
android:text="Text"
android:gravity="center" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="3"
android:layout_weight="0.75"
android:text="Text that is longer than other cells" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Text" />
</TableRow>
</TableLayout>
Yojimbo, you are right, however if you use
android:layout_weight
you must remember about replacing (in this special case) android:layout_width="wrap_content" with
android:layout_width="0dp" .
Here you have a nice reference.
Related
I am following tutorial from the book "Android Apps for Absolute Beginners 3rd Edition", and I am stuck with nested LinearLayout for android project in API 19 (4.4.2): Parent LinearLayout is horizontal and it is supposed to hold two child LinearLayout which are vertical and the end result should be like this:
But what I get is:
I tried several times, cross checked code in book, and explanations but I can't get it right.
Here is content of activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal" android:background="#drawable/galaxyinfoscreen" >
<LinearLayout android:orientation="vertical" android:layout_margin="12dip"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#00000000">
<TextView android:text="#string/hello_world" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="48dip" android:textStyle="bold" />
<TextView android:text="#string/galaxy_name" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_solar" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_habit" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_colony" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_pop" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_fleet" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_ships" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:orientation="vertical" android:layout_margin="33dip"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#00000000" >
<TextView android:text="#string/name_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/name" />
<TextView android:text="#string/solar_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/solar" />
<TextView android:text="#string/habit_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/habit"/>
<TextView android:text="#string/colony_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/colony" />
<TextView android:text="#string/pop_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/pop" />
<TextView android:text="#string/fleet_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/fleet" />
<TextView android:text="#string/ships_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/ships"/>
</LinearLayout>
</LinearLayout>
What could be missing from this file? What should I do to get desired result?
try this
<?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:background="#drawable/galaxyinfoscreen"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="48dip"
android:text="#string/hello_world"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dip"
android:background="#00000000"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_name"
android:textColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_solar"
android:textColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_habit"
android:textColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_colony"
android:textColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_pop"
android:textColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_fleet"
android:textColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_ships"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dip"
android:background="#00000000"
android:orientation="vertical" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_data"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/solar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/solar_data"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/habit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/habit_data"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/colony"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/colony_data"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/pop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pop_data"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/fleet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fleet_data"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/ships"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ships_data"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
"Glaxy Information Screen" TextView is inside first verical LinearLayout. As this text view is taking more space due to its margin and text length hence leaving less space for second linearlayout, resulting into wrap of text for sencond verical layout.
To solve the problem, add one more linear layout with orientation as horizontal as parent of both the vertical layout and add the "Glaxy Information Screen" text view as direct child of top parent.
you may need to make some adjustment to the margin values to aling the layouts.
In the second LinearLayout, the margin parameter is android:layout_marginTop="33dip
You forgot to put Top after margin.
;)
The second LinearLayout doesn't have enough width to accommodate the string and it gets wrapped. If you absolutely must use nested LinearLayout, you should use layout_weight instead of using width with wrapped content. In the example below, I have also moved the title out of the nested LinearLayout to another vertical one.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:background="#drawable/galaxyinfoscreen" >
<TextView android:text="#string/hello_world" android:textColor="#FFFFFF"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:gravity="center" android:textStyle="bold" />
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout android:orientation="vertical" android:layout_margin="12dip"
android:layout_width="0dp" android:layout_weight="3" android:layout_height="wrap_content"
android:background="#00000000">
<TextView android:text="#string/galaxy_name" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_solar" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_habit" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_colony" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_pop" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_fleet" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_ships" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:orientation="vertical" android:layout_margin="12dip"
android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"
android:background="#00000000" >
<TextView android:text="#string/name_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/name" />
<TextView android:text="#string/solar_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/solar" />
<TextView android:text="#string/habit_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/habit"/>
<TextView android:text="#string/colony_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/colony" />
<TextView android:text="#string/pop_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/pop" />
<TextView android:text="#string/fleet_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/fleet" />
<TextView android:text="#string/ships_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/ships"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
With your current code i have two suggestions:
First:
android:singleLine="true"
add this tag to all your list views, so this will maintain symmetry in all your textView placement.
Secondly:
Keep a single Parent LinearLayout with orientation vertical, then have multiple LinearLayout with horizontal orientation and two TextView inside it.
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" />
I am trying to do my first complex GUI, but now i can't to solve this problem.
The first column of the first two rows only needs to contain the label, while the second column of the first two rows must occupy the remaining space.
In this snapshot the problem that i noticed is that the first column is larger than i would like.
This is the piece of code that implements that piece of layout.
...
...
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/linear_layout_background"
android:stretchColumns="*"
android:shrinkColumns="*">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp" >
<TextView
android:id="#+id/textViewPlateValueLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/plateValue"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/productID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:ems="5"
android:text="#string/blank"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp" >
<TextView
android:id="#+id/ztlLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ztl"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/ztlShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:text="#string/blank"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center" >
<TextView
android:id="#+id/isAllowed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/blank"
android:background="#drawable/back"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
</TableLayout>
...
...
In addition, since they are really impractical, I would like to ask you some advice on the best approaches to use than this.
You can try using layout_weight like this:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="horizontal"
tools:context=".MainActivity" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#ff00ff"
android:stretchColumns="*"
android:shrinkColumns="*">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<TextView
android:id="#+id/textViewPlateValueLabel"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Label1:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/productID"
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#00ff00"
android:ems="5"
android:text="Some Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<TextView
android:layout_weight="3"
android:id="#+id/ztlLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Label2:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_weight="7"
android:id="#+id/ztlShow"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#00ff00"
android:text="Some Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center" >
<TextView
android:id="#+id/isAllowed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text"
android:background="#0088ff"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
</TableLayout>
</LinearLayout>
I wouldn't use TableLayout, if I were you. I'd probably use LinearLayout or RelativeLayout. You can get the same effect with some of the XML attributes. This is akin to using HTML's table attribute vs. using divs to simulate tables.
So, instead of a table, you can have LinearLayout inside of LinearLayout to simulate a table.
Although canDroid, could be sufficient to some of us, it didn't worked for me, I tried all kind of tricks to make the TableLayout to work. I found LinearLayout much easier to use, here is an example of TableLayout "like" layout using LinearLayout, few cells with a thumbnail, and few without.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="94dp"
android:layout_margin="5dp"
android:text="#string/nut1" />
</LinearLayout>
<View
android:layout_width="395dp"
android:layout_height="2dp"
android:background="#color/colorPrimary"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="0dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<ImageView
android:layout_width="94dp"
android:layout_height="94dp"
android:adjustViewBounds="false"
android:background="#drawable/one"
android:contentDescription="#string/nut3"
android:cropToPadding="false"
android:saveEnabled="false"
android:scaleType="center" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="94dp"
android:layout_margin="10dp"
android:text="#string/nut3" />
</LinearLayout>
</LinearLayout>
I've been looking for an answer to this for a long long long time.
I have the following code:
<TableRow
android:id="#+id/tableRow106"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:visibility="gone"
android:background="#drawable/b02_light_bar">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button35"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/b02_play_blue"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp"
>
<TextView
android:id="#+id/textView20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="#string/interaction2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#41c4dd"
android:text="#string/interaction2cont"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
</TableRow>
And my text in textview21 still gets cut off if it is too long.
Anyone know how to solve this?
I promise you, I tried everything!
I have copied your code and string and yes the problem is there..
I got one solution for you and that's
Remove android:padding="10dp" from TableRow tag and apply that in the LinearLayout right under the tableRow.
<TableRow
android:id="#+id/tableRow106"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:background="#drawable/b02_light_bar">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
>
<Button
android:id="#+id/button35"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/b02_play_blue"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp"
>
<TextView
android:id="#+id/textView20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="#string/interaction2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#41c4dd"
android:text="#string/interaction2cont"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
</TableRow>
use the attribute android:maxLines="3"
Change your textview to
<TextView
android:id="#+id/textView21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#41c4dd"
android:maxLines="3"
android:text="#string/interaction2cont"
android:textAppearance="?android:attr/textAppearanceSmall" />
I'm developing an Android app.
I have this layout:
I don't want to let a textview fill a entire column. As you can see on previous image there is a TextView surrounded with a blue rectangle (in fact is selected). This is the XML code that creates that TableRow:
<TableRow>
<TextView
android:id="#+id/txtFactLoc"
android:layout_span="2"
android:gravity="center_vertical|right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/layout_fac_location"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/factLocVal"
android:layout_span="4"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:layout_height="match_parent"
android:background="#color/textview_background"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtConFactLoc"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/layout_confirm"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="#+id/rGroupFactLoc"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/rFactLocYes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="#string/layout_yes" />
<RadioButton
android:id="#+id/rFactLocNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/layout_no" />
</RadioGroup>
</TableRow>
Is inside a TableLayout with eight columns. This is the beginning for TableLayout:
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_margin="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*"
android:stretchColumns="*">
<TableRow>
<TextView
android:id="#+id/txtPONo"
android:layout_weight=".125"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="#string/layout_po_no"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/pONoVal"
android:layout_weight=".125"
android:layout_width="0dip"
android:paddingLeft="10dp"
android:layout_height="match_parent"
android:background="#color/textview_background"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtIndNo"
android:layout_weight=".125"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="#string/layout_ind_no"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/indNoVal"
android:layout_weight=".125"
android:layout_width="0dip"
android:paddingLeft="10dp"
android:layout_height="match_parent"
android:background="#color/textview_background"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtTimeIn"
android:layout_weight=".1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="#string/layout_time_in"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/timeInVal"
android:layout_weight=".15"
android:layout_width="0dip"
android:paddingLeft="10dp"
android:layout_height="match_parent"
android:background="#color/textview_background"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtTimeOut"
android:layout_weight=".1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="#string/layout_time_out"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/timeOutVal"
android:layout_weight=".15"
android:layout_width="0dip"
android:paddingLeft="10dp"
android:layout_height="match_parent"
android:background="#color/textview_background"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
Some textViews have a background color. As you can see all of them fill its columns and I don't want that because this form looks very ugly.
How can I change TextView width? If I have set android:layout_span="2" I can't change its width.
With android:stretchColumns, you can decide which columns are allowed to be streched (put it in the TableLayout tag).
android:stretchColumns="0"
android:stretchColumns="0,1,2"
android:stretchColumns="*"