Wrap Text in android? - android

I want to achieve wrap text in android. I am using following attributes but still couldnt be able to achieve
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textview01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:scrollHorizontally="false"
android:text="#string/hello" /> // #String/hello <string name="hello">Hello,How are you world whatsup</string>
Anyone please help ?

use this
<TextView
android:id="#+id/textview01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="none"
android:scrollHorizontally="false"
android:text="#string/hello" />

I tried ur code by replacing #string/hello = "Hello,How are you world whatsup. Hello,How are you world whatsup" and it worked fine.
may be other views in ur layout are affecting your TextView
try adding "android:layout_weight="1""

Related

TextView and EditText overflow

I've got a need to display and TextView (label), EditText(Input) and TextView(suffix) in a line.
The issue I have is - if the label TextView is too long it The EditText and Suffix TextView and not drawn.
Here's my code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_weight="0"
android:padding="5dp"
android:text="Label"
android:id="#+id/label_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_weight="1"
android:id="#+id/input_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColorHint="#color/dark_grey"
android:textColor="#color/black"
android:hint="text.." />
<TextView
android:padding="5dp"
android:layout_weight="0"
android:text="Suffix.."
android:background="#color/lite_grey"
android:id="#+id/suffix_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
So what I want is - even if the label is over 2-3 lines, for an EditText to appear followed by another TextView.
Any pointers would be appreciated.
Thanks!
Edit:
I've added some 'diagrams' so you can understand what I want to do a bit better.
The label to the EditText can be arbitrary length(2/3 lines), so whenever the label finishes I want an EditText to start (which is followed by another TextView showing a suffix..)
..
![This shows a 2 line label and TextView..]
Edit 2: Thanks for the responses guys!! I think #questioner has really understood what I want to do i.e. I want your 3 views to move to other lines so that they behave like they were one view - and as he has suggested i'll have to find a library for this!
How about this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:padding="5dp"
android:text="Label"
android:id="#+id/label_text_view"
android:layout_width="100dp"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"/>
<EditText
android:layout_weight="1"
android:id="#+id/input_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColorHint="#color/dark_grey"
android:textColor="#color/black"
android:hint="text.."/>
<TextView
android:padding="5dp"
android:text="Suffix.."
android:layout_gravity="center_vertical"
android:background="#color/lite_grey"
android:id="#+id/suffix_text_view"
android:layout_width="100dp"
android:layout_height="wrap_content"/>
</LinearLayout>
If you want your 3 views to move to other lines so that they behave like they were one view - you should use external library for that.
Why not use a RelativeLayout instead of LinearLayout and then use android:layout_below="#+id/..." or android:layout_above="#+id/..." also android:layout_toRightOf="#+id/..." or android:layout_toLeftOf="#+id/..."
Set
android:layout_weight="1"
for each view so that they all occupy the same amount of horizontal space.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1">
Try this or please expand a little more.

Android AutoCompleteTextView suggestions overlapping the TextView

I am making an application using Google maps. I am using AutoCompleteTextView to get suggestions of places. The output is as follows :
As you can see from the image, the border of the suggestion box is overlapping the TextView. I am using custom item layout with a Textview inside a Linear Layout.
<?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:background="#fff"
android:orientation="horizontal" >
<TextView
android:id="#+id/resultValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:textColor="#474040"
android:textSize="15sp" />
</LinearLayout>
Is there a way to bring the suggestion window down and to remove or change the colour of the grayish border of the suggestion window ?
Was doing the same thing as in the accepted answer, but was still having the overlap issue. To fix that make this call:
autocompleteView.setDropDownVerticalOffset(0);
Try like this, android:popupBackground="#EFEEEC"// change according your border you want for the suggestion box
<AutoCompleteTextView
android:id="#+id/autocomplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/text_area"
android:inputType="text|textNoSuggestions|textMultiLine"
android:paddingLeft="10dp"
android:popupBackground="#EFEEEC"
android:textColor="#333333"
android:textColorHint="#9c9c9c"
android:textSize="18sp"
android:completionThreshold="1" />
and auto_textview.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:textColor="#333333"
android:layout_margin="15dp"
android:textSize="16sp" >
</TextView>
text_area9.png
Final output will look like
Hope this help you.
Use a custom drawable like
AutoCompleteTextView txtNames= (AutoCompleteTextView)findViewById(R.id.editBox);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.drawable.customlist, restList);
txtRestNames.setAdapter(adapter);
and add customlist as
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cust_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:textSize="12dp"
android:singleLine="false"/>
Change the parameters/color to suit your needs. Try it....hope it helps

Text in TextView not shown in multiple lines - it gets truncated in a single line

Below is an outline of my layout. I have my ScrollView inside another LinearLayout because I would be adding more views to it in runtime.
Anyway, the problem is - the text in the TextView is always truncated to a single line, and is never shown in multiple lines.
Is there any way to make it display a multilined TextViw without having to set an arbitrary number of lines using android:lines or android:maxLines?
Thanks.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="#drawable/background"
android:id="#+id/XyzLayout"
android:paddingRight="10dp">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#drawable/background"
android:fillViewport="true">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical"
android:layout_marginBottom="0dip" android:layout_marginTop="1dip">
<TextView android:id="#+id/textView1"
android:text="#string/String1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="20dip"
android:layout_marginRight="10dip" android:textSize="18dip"
android:typeface="sans" android:textStyle="bold"
android:layout_marginBottom="4dip"
android:inputType="text|textMultiLine"/>
<TextView android:id="#+id/textView2"
android:text="#string/String2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="20dip"
android:layout_marginRight="10dip" android:textSize="16sp"
android:typeface="sans" android:textStyle="bold"
android:layout_marginBottom="4dip"
android:inputType="text|textMultiLine"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
i've got this problem with a i5800 with CM7(2.3.7) and the emulator and works fine on a SGS-i9000 with CM9 (4.0.3).
The problem was setting the theme at the manifest:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault" >
I put " android:theme="#android:style/Theme.Holo " and if the device doesn't have it, the textview doesn't allow MultiLine.
You can use the library " holoeverywhere " to port the holo theme to all devices.
Regards.
Try deleting the setting android:inputType="text".
Just had the same problem. I had android:multiLines="2", then I tried android:lines="2", then tried adding android:singleLine="false", but still my EditText would only show one line. I could scroll horizontally to get to the end of my line. What ended up working was deleting the setting android:inputType="text" . This allowed me to type in a long line that would wrap around to a second line.
It could be false by default but did you try to add this in your TextView
android:singleLine="false"
-serkan
To add to #KNU's answer...
Here's a good related answer showing that you can use a different theme depending on the version of Android it is running on - just create a versioned styles folder.
Answer here: TextView won't break text
Set input type as inputType="text|textMultiLine". This made to resolve my issue.
<TextView
android:id="#+id/itemTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text|textMultiLine"
android:textSize="#dimen/text_size_12"
android:layout_gravity="center"
android:gravity="center"
android:text="Your Text Here"/>

How to add margin between radiobutton ant it's drawable?

This my current layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#F5F5DC"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RadioButton android:id="#+id/radio_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/flag_dk"
android:textColor="#000000"
android:layout_gravity="center_horizontal"
android:drawablePadding="10dip"
android:text="Danish" />
<RadioButton android:id="#+id/radio_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/flag_en"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dip"
android:drawablePadding="10dip"
android:textColor="#000000"
android:text="English" />
</RadioGroup>
</LinearLayout>
</ScrollView>
I get this:
I would like to have some space (margin) between radiobutton an the flag (it's drawable). Is it even possible?
You can do like the following:
<android.support.v7.widget.AppCompatRadioButton
android:layout_width="match_parent"
android:layout_height="#dimen/view_size"
android:button="#null"
android:drawablePadding="100dp"
android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
android:text="label" />
In my case, where I have a custom drawable shape, adding android:paddingDrwable attribure did not work but adding android:paddingLeft="5dp" did.
Where you are setting the image and the text give blank spaces before it.
for example: radiobutton.setText(" "+Text);.You will see the desired output.
I don't think it is possible to add space between the image and the radio button using the android apis. However, the answer to your question I think is to add some space in the image itself.
Use Relative Layout instead of Linear Layout it gives android:layout_margingleft & android:layout_margingRight to drop your radio buton & Images as well.
Also give android:padding="10dip"
Try it it will definitely work!!!!

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