TextView cuts off text when it is long enough - android

I have strange problem with TextView, it cuts off part of the text at the end. My layout looks like
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|center_horizontal"
android:gravity="top|center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|center_horizontal"
android:gravity="top|center_horizontal"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_marginBottom="5dp">
<Button
android:id="#+id/btnPreviousQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selector_arrow_left"
android:clickable="true"
android:visibility="gone" >
</Button>
<TextView
android:id="#+id/txtQuestion"
style="#style/question_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top|center_horizontal"
android:layout_weight="1"
/>
<Button
android:id="#+id/btnNextQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#drawable/selector_arrow_right"
android:clickable="true" >
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="horizontal" >
<WebView
android:id="#+id/wvMultimediaQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginLeft="50dp"
android:layout_marginRight="55dp"
android:layout_weight="1"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
and txtQuestion cuts off text when it is long enough. What is wrong, does anybody know ?

Make use of these attributes
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
will append "..." at the end. But this will not solve problem in honeycomb tab
So for honeycomb tablet add the following atttibute also
android:singleLine="true"
On the other hand if you require marquee effect
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true

Yes there are some attributes you need to set, but first let us know what type of textview do you want exactly, single line or multi line?
There are some attributes you can take care of:
android:singleLine="true" // or false
android:ellipsize="marquee" // must check
android:lines="1"

Set below properties in layout file. It works fine for me
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"

If you expect differing lengths of text for your view or you're going to change the textSize of different instances of your TextView then you should use View.addOnLayoutChangeListener().
See an example here: https://stackoverflow.com/a/44069734/1402087

Set the layout_gravity on the TextView to fill

You need to set
android:minLines="2"

For me it I realised I was using the layout view of a different device to the one I was testing with. When I corrected this, I could see the textlayout was way too wide so I used this setting to reign it in:
android:layout_width="330dp"

Tried all the solutions provided here but none of these helps, finally got the solution using android:layout_width="0dp" instead of android:layout_width="fill_parent" in textview.

Related

How to make vertical scrolling textview's in Android

I have been looking for a post to create vertical scrolling multiple textviews. similar to one shown here http://vertical-scroller.vbarsan.com/
But all post are related to creating horizontal scrolling (Marquee) textview.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"/>
I hope this helps
Have main layout as ScrollView ,Create vertical LinearLayout as child of ScrollView and create (number of textview you required ) textViews inside LinearLayout.
you should change android:layout_height
as per your code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#FF4081"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="1st Line !" />
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="2nd line !"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="3rd line !" />
</LinearLayout>
</ScrollView>
You have 2 choice for that:
1) Use Native way: using thread, put 10 spaces before any text and in each second remove left side space and increase right space and so on, until it's limits. Hope you understood. Predefined TextView's below properties also uses this method.
2) Use predefined control TextView with below properties:
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
use this example code below it will do a marquee like html
<TextView
android:id="#+id/mywidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="Simple application that shows how to use marquee, with a long text" />

Aligning two textviews in a listview

Here's what I have:
There are options and there are content to every option. Option numbers (A, B, C, D) are in a separate textview and their contents are in a separate textview.
All I'm trying is aligning the option number with the first line of the option content. I tried setting the constant paddingTop, but as the number of lines in the option-content changes, it goes out of alignment. Any suggestions upon how to do it?
Here's part of the xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/options"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<TextView
android:id="#+id/option_number"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="10"
android:text="A"
android:paddingLeft="5dp"
android:textSize="17sp"
android:textStyle="bold"
android:textColor="#color/charcoal"/>
<TextView
android:id="#+id/option_content"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="100"
android:textSize="17sp"
android:gravity="center|left"
android:paddingRight="20dp"
android:text="option content...."
android:textColor="#color/charcoal"/>
Can I do it by getting the paddingTop of option content dynamically and setting the same padding to the option number?
Try with below.
Replace this in your xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/options"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="5">
<TextView
android:id="#+id/option_number"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:text="A"
android:maxLines="4"
android:textColor="#color/charcoal"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/option_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:maxLines="4"
android:text="option content...."
android:textColor="#color/charcoal"
android:textSize="17sp" />
</LinearLayout>
And It's Done.
Surely it will help you.
Set android:gravity="top" for option_number TextView android:gravity="top|left" for option_content. Or, User a Relative Layout and use layout_aligntop
Try setting android:layout_alignBaseline="#id/option_number" on option_content
You can use Relative layout instead of linear layout, but you wll have to change your xml a bit. So if you decide to use it you can just set the next property to first TextView
android:layout_alignTop="#+id/option_content"
It should help you.
use: android:layout_centerVertical="true".
Suggestion, can use the following three in combination to easily achieve what you want:
1) CenterVertical
2) ToRightOf
3) RelativeLayout.
e.g:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/options"
android:layout_width="match_parent"
android:layout_height="80dp">
<TextView
android:layout_centerVertical="true"
android:id="#+id/option_number"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="A"
android:paddingLeft="5dp"
android:textSize="17sp"
android:textStyle="bold"
android:textColor="#color/charcoal"/>
<TextView
android:layout_toRightOf="#id/option_number"
android:layout_centerVertical="true"
android:id="#+id/option_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="option content...."
android:textColor="#color/charcoal"/>

How to put gap between Text and ImageView in EditText in android?

I am using the EditText with drawableLeft property and set ImageView in Right side for ClearText. My Question is how to put gap between text and Imageview in EditText?
Please help me.
Actually I have Like this,My Screenshot is,
Actually I want to Like this,
Create Gap Between Text and ImageView. How it is Possible?.
My xml file is,
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/edtSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_margin="5dip"
android:drawableLeft="#drawable/search"
android:drawablePadding="10dip"
android:hint="Find"
android:imeOptions="actionNext"
android:inputType="text"
android:singleLine="true" >
</EditText>
<ImageView
android:id="#+id/imgSearchClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/edtSearch"
android:layout_centerVertical="true"
android:layout_marginRight="10dip"
android:contentDescription="#string/app_name"
android:src="#drawable/clear" />
</RelativeLayout>
Okay i got your Question now...you have to use Search view instead of edittext
Here is link:- Check it out
Only this is a solution of your problem
i am using LinearLayout for this
<LinearLayout
android:id="#+id/linear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="#+id/chatText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textMultiLine"
android:padding="8dp" />
<ImageView
android:id="#+id/buttonSend"
android:layout_width="50sp"
android:layout_height="50sp"
android:padding="5dp"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Had the same problem a while ago fixed it with drawablePadding
Hello
Use Linear layout with weight instead of Relative as m showing below:-
<LinearLayout
width
hight
orientation="horizontal">
<EditText
android:id="#+id/edtSearch"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:drawableLeft="#drawable/search"
android:drawablePadding="10dip"
android:hint="Find"
android:imeOptions="actionNext"
android:inputType="text"
android:singleLine="true" >
</EditText>
<ImageView
android:id="#+id/imgSearchClear"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dip"
android:contentDescription="#string/app_name"
android:src="#drawable/clear" />
</LinearLayout>
if you found any issue regarding this please let me know..i love to help you
or in relative layou you can use drawable padding
Spartacus thanks :)
I can try to implement your code but It Like this,
and I want to Like this,
Set the right padding of EditText to the width of Clear button. Set all the dimension in dimen folder so that it will be compatible with all device sizes.

Set Textview + Edittext + Button

I want to put in the same row a TextView, and Edittext and a button but I am having the problem that the button is not aligned properly to left and in small screens edittext fills entire with.
Small screen:
Big Screen:
My codification is as follows:
<LinearLayout
android:id="#+id/layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/address_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/address_textview"
android:textStyle="bold" />
<EditText
android:id="#+id/address_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/address_textview_hint"
android:imeActionLabel="#string/search_button"
android:imeOptions="actionDone"
android:inputType="textCapWords"
android:nextFocusDown="#id/address_edittext"
android:nextFocusUp="#id/address_edittext"
android:singleLine="true" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right" >
<Button
android:id="#+id/go_button"
android:layout_width="50dp"
android:layout_height="35dp"
android:text="Go" />
</RelativeLayout>
</LinearLayout>
Apply a weight to your EditText so it will take up as much room as it can while letting the other two elements do the normal wrap_content. To do this, remove the relative layout container and then change the EditText width to "0dp" and give it a layout_weight of "1" as follows:
<LinearLayout
android:id="#+id/layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/address_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/address_textview"
android:textStyle="bold" />
<EditText
android:id="#+id/address_edittext"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="#string/address_textview_hint"
android:imeActionLabel="#string/search_button"
android:imeOptions="actionDone"
android:inputType="textCapWords"
android:nextFocusDown="#id/address_edittext"
android:nextFocusUp="#id/address_edittext"
android:singleLine="true" />
<Button
android:id="#+id/go_button"
android:layout_width="50dp"
android:layout_height="35dp"
android:text="Go" />
</LinearLayout>
First, many people will tell you that hint is Android's solution for not needing the label. I don't care if you use the label or not but it does save you space, especially on smaller screens. That was just an FYI.
Now, your RelativeLayout that only has a Button appears to be useless...I would remove that. You can use layout_weight so that each View takes up the appropriate amount of space. Make sure to make the layout_width="0dp". So it may look something like
<LinearLayout
android:id="#+id/layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/address_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="#string/address_textview"
android:textStyle="bold" />
<EditText
android:id="#+id/address_edittext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="#string/address_textview_hint"
android:imeActionLabel="#string/search_button"
android:imeOptions="actionDone"
android:inputType="textCapWords"
android:nextFocusDown="#id/address_edittext"
android:nextFocusUp="#id/address_edittext"
android:singleLine="true" />
<Button
android:id="#+id/go_button"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:text="Go" />
</LinearLayout>
Here I used 2,3,1 for the weights of your TextView, EditText, and Button respectively. You may need to change those to get exactly what you want but that should give you a start.
Layout weigth is ideal for designing layouts that adjust to screen size. However, make sure to set layout_width to 0dp, or it won't work properly.
Use like this:
android:layout_width="0dp"
android:layout_weight="1"
I'm going to assume you mean the button is not properly aligned to the right.
It's because your RelativeLayout's android:width="wrap_content", but it should be android:width="match_parent".
Also, you'd be better off setting your EditText's android:width="0dp" and adding android:weight="1" so that it expands/contracts between screen sizes.

Add unit symbol at the end of the EditText

I have one EditText witch is of type numberDecimal. I would like to have the unit symbol (for instance m, km, kg, g) at the end of the value. I have found many posts here at stackoverflow that tells to use TextWatcher or InputFilter, but what I would really love to is to restrict this unit symbol to not being editable for the user.
So when you edit the value in the textbox, you can't move the courser to manipulate/delete the symbol. It is basically not a editable part of the value.
I'm sure this is possible to achieve, but Im not sure how much custom code I need to write to make it work. Are there any SDK support for this?
Ismar
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.70"
android:gravity="center_horizontal"
android:padding="4dip" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/browseurl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dip"
android:imeOptions="actionGo"
android:textColor="#BCBCBC"
android:textSize="14dip"
android:typeface="serif" />
<ImageButton
android:id="#+id/cross"
android:layout_width="25dip"
android:layout_height="25dip"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:background="#android:drawable/ic_menu_close_clear_cancel"
android:clickable="true"
android:focusable="false" />
</RelativeLayout>
</LinearLayout>
Replace the ImageButton with either a textbox or a image button for units.
Thanks for the hints. Here is my solution, I have one linearlayout with 20dip margin to the left and right. Inside of the layout I have one EditText and one TextViw. I set weight to 1 on the EditText so it fills any remaining space in the parent view.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:orientation="horizontal" >
<EditText
android:id="#+id/value_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/value_unit_symbol"
android:layout_width="wrap_content"
android:layout_height="25dip"
android:text="kg"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

Categories

Resources