Text wrap in TextView within a Tab - android

First off, sorry about the large screen. I am trying to get the text to wrap but am currently unable to do so. I have tried android:layout_width="fill_parent", android:scrollHorizontal="false", android:width="0dip" all of which suggested in another question. Does anyone have any idea how I can achieve text wrapping? Here's a sample of the xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="2">
<TableRow>
<TextView
android:layout_column="1"
android:gravity="center"
android:background="#drawable/lgrayborder"
android:paddingRight="5dip"
android:paddingLeft="5dip"
android:id="#+id/chatUser1"/>
<TextView
android:layout_column="1"
android:gravity="left"
android:background="#drawable/lgrayborder"
android:paddingLeft="5dip"
android:id="#+id/chatComm1"/>
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:gravity="center"
android:background="#drawable/lgrayborder"
android:paddingRight="5dip"
android:paddingLeft="5dip"
android:id="#+id/chatUser2"/>
<TextView
android:layout_column="1"
android:gravity="left"
android:background="#drawable/lgrayborder"
android:paddingLeft="5dip"
android:id="#+id/chatComm2"/>
</TableRow>
</TableLayout>
</ScrollView>
Update: I have tried setting attributes in the ScrollView, TableLayout, and TableRow in hopes that it would force the TextViews to wrap but to no avail. Still looking for a solution to this.

Have you already tried to use
android:maxEms="int"
in combination with ellipsize? This should solve your problems.

I had the same issue with TableLayout and fixed it by setting column shrinkable to "true" like this:
TableLayout tl = (TableLayout)findViewById( R.id.ViewTaskTable );
tl.setColumnShrinkable( 0, true );
HTH

You need to set the ellipsize property of the TextView.

Related

TableLayout refuses to match_parent

I have an xml layout which serves as an item in a ListView. The thing is: when it's added there, the item's width isn't stretched to match_parent, it wraps content instead. It is used in a ListView, so its width needs to be match_parent. I've been reading about it all over stackoverflow, trying every solution availible, but I have had zero result: layout_weight set to 1 does nothing to my layout, stretching columns has given me the best result in terms of width, but in terms of layout itself it failed miserably.
Is there anything that can be done here?
<?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="wrap_content"
android:descendantFocusability="blocksDescendants">
<TableRow
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<CheckBox
android:id="#+id/trackCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:clickable="false"
android:duplicateParentState="true" />
<TextView
android:id="#+id/trackNumberText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="00."
android:textColor="#android:color/black"
android:textSize="18sp" />
<TextView
android:id="#+id/trackTitleText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_weight="1"
android:text="Title"
android:textColor="#android:color/black"
android:textSize="18sp" />
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/trackArtistText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_weight="1"
android:text="Artist" />
</TableRow>
</TableLayout>
Add android:stretchColumns="*" property in your TableLayout
android:stretchColumns
The zero-based index of the columns to stretch. The column indices
must be separated by a comma: 1, 2, 5. Illegal and duplicate indices
are ignored. You can stretch all columns by using the value "*"
instead. Note that a column can be marked stretchable and shrinkable
at the same time.
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:descendantFocusability="blocksDescendants">
.....
</TableLayout>
Hope this will help.
I think what you want is tableLayout.setStretchAllColumns(true);. Unfortunately you cannot set that in xml, perhaps place it in your adapter.
None of the mentioned solutions have helped me, so trying to solve this for 3 days I found a solution myself. Unfortunately, the solution is programmatical, the following code is to be added to your custom adapter:
trackCheckBox.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
trackNumberText.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
int width = context.getResources().getDisplayMetrics().widthPixels - trackCheckBox.getMeasuredWidth() - trackNumberText.getMeasuredWidth();
trackArtistText.setWidth(width);
trackTitleText.setWidth(width);

android weight sum

i have defined weightsum for one 1 tablerow and layout_weight. this is what i am doing
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1" >
<TextView
android:id="#+id/add"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_weight="0.2"
android:text="#string/restaurant_add"
android:textStyle="bold" />
<TextView
android:id="#+id/Restaurant_add"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_weight="0.8"
android:clickable="true" />
</TableRow>
i am filling the data to Restaurant_add dynamically.. but when i fill the data to Restauant_add, even though i have set the layout_weight to 0.8, it is overriding the data present in android:text="#string/restaurant_add".
what is the mistake i am doing?
Thanks:)
Can you try to set android:layout_width="0dp" to your two TextView ?
Also, your TextView's id Restaurant_add is the same as your string #string/restaurant_add. Make sure that you modify the layout and not your string !
Set both your android:layout_widths to "0dp".

Issue with Relative/Table Layout

I want the TextView to be always on the top of each EditText, on all of device's screens. First, I've tried to do something with RelativeLayout, but it's not working. Now, I'm trying with TableLayout. I would like your opinion for the best layout for this use!
Here is 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="fill_parent"
android:stretchColumns="2"
android:background="#drawable/back" >
<TextView android:id="#+id/mathimatika"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Mathimatika Kateuthinsis"
android:textColor="#09074c"
android:textSize="14px"
android:gravity="center" />
<TableRow>
<TextView
android:layout_column="1"
android:text="Profwrika a"
android:padding="13dip"
android:textColor="#09074c"
android:textSize="10px"/>
<TextView
android:text="Profwrika b"
android:gravity="center"
android:textColor="#09074c"
android:textSize="10px" />
<TextView
android:text="grapta"
android:gravity="right"
android:padding="13dip"
android:textColor="#09074c"
android:textSize="10px" />
</TableRow>
<RelativeLayout>
<EditText
android:id="#+id/input11"
android:layout_width="60px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:numeric="decimal|signed"
android:layout_below="#id/vathmos1"
android:layout_marginLeft="13dip" />
<EditText
android:id="#+id/input21"
android:layout_width="60px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:numeric="decimal|signed"
android:layout_toRightOf="#id/input11"
android:layout_below="#id/vathmos1"
android:layout_marginLeft="25px" />
<EditText
android:id="#+id/input31"
android:layout_width="60px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:numeric="decimal|signed"
android:layout_toRightOf="#id/input21"
android:layout_below="#id/vathmos1"
android:layout_marginLeft="25px" />
</RelativeLayout>
</TableLayout>
Well, you can do it with a RelativeLayout, I dont understand why you say you cant do it. But if you want to use it with a TableLayout, then you need to have two TableRow, one with the TextViews and the other with the EditText. Thus, the children of the TableLayout will be the TableRows.
However, I would recommend that you use a RelativeLayout, its cheaper because it doesnt have to calculate stuff and its only one level in the stack.
You can define your three EditText first, then the three TextViews that are above the each EditText, and if you want them to be centered, then you can align both the left and the right side to the EditTexts.
I hope this helps, let me know what you think

Android TableLayout width issue

I'm using TableLayout to display data.
Text of the TextViews of the right column will be set when activity calls onCreate().
Now, as you can see in the following image that my address text can be long and it should be wrapped.
So I set android:layout_width="wrap_content". but it still take a width of screen size to wrap data.
How can I overcome from this issue?
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"
android:padding="5px">
<TableRow>
<TextView android:text="Job#"
android:paddingRight="5px" />
<TextView android:id="#+id/DetailJobNo" />
</TableRow>
<TableRow>
<TextView android:text="Address"
android:paddingRight="5px" />
<TextView android:id="#+id/DetailAddress"
android:layout_width="wrap_content"
android:text="Address Address Address Address Address Address Address Address "/>
</TableRow>
</TableLayout>
Adding android:shrinkColumns="1" to TableLayout solves my issue.
Can you try setting setHorizontallyScrolling to the DetailAdress TextView to false?
#Vikas, its good that you have solved your problem.
BUt I would still recommend to use HorizontalScrollView for security purposes. If at all few chars are not visible, then horizontal scrollbar will help to manage that. XML text :
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginBottom="10dp" >
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5px">
......
......
ADD YOUR ROWS
</TableLayout>
</HorizontalScrollView>
Its always better to take care of the unexpected.

Indent bullet list in TextView

I have a TextView which I fill with text from a string resources in strings.xml. The string resource contains < li > elements to create a bullet list inside the TextView. My problem is that I want to control the indention of lines in the bullet list that span over more than one line. Default the text isn't indented past the bullet so it looks kind of ugly. Is it possible to do this with style parameters or to create bullets in some other way?
Thanks in advance.
edit:
Is it really answered? I don't have any problems producing the bullet list, as described in those links but I'm having problems getting the layout correct. The indentation is like this:
text that go beyond the width
of the line.
And I want the "of the line" to at least start indented as far as the text after the bullet. That's what I try to achieve.
I'm suprised that there seems to be noone with this problem. I mean, bullet list can't be that uncommon in about-dialogs, FAQ etc and a bullet doesn't have to contain too much text to span more than one row and run into this problem.
Anyway, I got to solve it like this for now:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="#+id/ScrollViewTipsLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/TipsLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_height="wrap_content"
android:id="#+id/TableLayout01"
android:layout_width="wrap_content"
>
<TableRow>
<TextView android:id="#+id/tvIngress"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#+string/tv_picking_content_ingress"
android:layout_span="2"
android:singleLine="false"
android:layout_weight="1"
/>
</TableRow>
<TableRow>
<TextView android:id="#+id/tvCleaningDot1"
android:layout_height="wrap_content"
android:text="•"
android:singleLine="false"
/>
<TextView android:id="#+id/tvCleaningFirst"
android:layout_height="wrap_content"
android:text="#+string/tv_picking_content_first"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="left"
android:singleLine="false"
/>
</TableRow>
<TextView android:id="#+id/tvCleaningDot2"
android:layout_height="wrap_content"
android:text="•"
android:singleLine="false"
/>
<TextView android:id="#+id/tvCleaningSecond"
android:layout_height="wrap_content"
android:text="#+string/tv_picking_content_second"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="left"
android:singleLine="false"
/>
</TableRow>
</TableLayout>
</RelativeLayout>
I use it to present static text in a bullet list so I don't bother to create the bullet + text dynamically in code. If anyone have any suggestion how to accomplish the same thing in a better way, please enlight me.
Btw, if going with the solution suggested in second link above:
android:text="<ol><li>item 1\n</li><li>item 2\n</li></ol>
The second, third etc. row in a bullet that span over more than one row won't get same indention as first line, which is quite ugly.
Thank you #Bjorn
You can also do something like bellow.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/point"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Your Text Here"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="14sp" />
</LinearLayout>
The way I solved this problem was by using a RelativeLayout and marginLeft. The marginLeft will put a blank margin between it and the previous item.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarTrackVertical="#drawable/scrollbar_vertical_track"
android:scrollbarThumbVertical="#drawable/scrollbar_vertical_thumb"
android:scrollbarSize="12dip">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10sp">
<TextView
android:id="#+id/body_text3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="3sp"
android:text="Main paragraph of text, before the bulleted list"
android:textSize="15sp" />
<TextView
android:id="#+id/type1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="3sp"
android:text="• First bullet"
android:textSize="15sp"
android:layout_below="#+id/body_text3"
android:layout_marginLeft="25dp" />
<TextView
android:id="#+id/type2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="3sp"
android:text="• Second bullet"
android:textSize="15sp"
android:layout_below="#+id/type1"
android:layout_marginLeft="25dp" />
</RelativeLayout>
</ScrollView>
Just trying to point out the key answer of the question:
to create an bullet list, use TableLayout with two columns for each row. One column for TextView of a bullet and the other one for the text
to make text TextView fill the rest empty TableRow and indented at new line, set the weight to 1. You can set the bullet weight to zero or just simply not set the bullet weight and let it empty
based on my experience, changing width parameter do not affect the text and the bullet. So you can leave it empty or set it to anything you want.
Example:
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/bullet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/bullet"/>
<TextView
android:id="#+id/TextView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="this is the text of a bullet list"/>
</TableRow>
</TableLayout>

Categories

Resources