Custom Spinner TextView is being cut off - android

So in the attached screen shot and the code sample you can see my custom spinner. As you can see my text is getting cut off no matter what I try to do. The nine patch image is set up correctly with the text padding on it too. I have right just about everything and am at a complete loss...
Custom spinner
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/spinner"
android:textColor="#555"
android:textSize="22sp"
android:textStyle="bold"
android:typeface="normal"
android:layout_width="wrap_content"
android:layout_height="40sp"
android:gravity="center_vertical|left"
android:singleLine="true" />
Implementing custom spinner
<Spinner
android:id="#+id/spinner_both20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/b_both20"
android:layout_alignTop="#+id/b_both20"
android:layout_marginLeft="4sp"
android:layout_marginRight="5sp"
android:layout_toRightOf="#+id/b_both20"
android:background="#drawable/buttons"
android:padding="20sp" />
Java
ArrayAdapter<CharSequence> aBoth = ArrayAdapter
.createFromResource(getActivity().getApplicationContext(),
R.array.d20both, R.layout.spinner_settings)
I'm super frustrated to be spending this many hours on something so simple. Any help would rock!

Padding will cut cut into your inner text.

Related

How to achieve ellipsize(Three dots) in List item of Android List Item

Hi my ListView's list items layout is as below: Also attaching Image that shows the output of this layout . In the above output image we can see the text present in 2nd line over laps with right aligned TextView. I want 3 dots to be placed at the end of Text with out overlap.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="16dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/sname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/name"
android:layout_below="#+id/name"
android:layout_marginTop="15dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/abbr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/sname"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
Can anyone help me in solving this issue ?
Thanks in Adavnce
Just add these layout attributes for your TextView
android:ellipsize="end"
android:maxLines="1"
This tells android you want your textview to be ellipsized at the end (add the 3 dots to the end of the text) and that you don't want your text to wrap to the next line (by setting the max lines).
The only thing you would need to then is make sure your TextViews don't overlap (the cri... portion). There are a number of ways to do this.
Move your abbr TextView to above your other TextViews and add android:layout_toLeftOf="#id/abbr" to your non-abbr TextViews
Redo your layout in general to make sure there is no overlap, using LinearLayouts would help achieve this with the benefit of things like weight.
Dynamically setting your widths once you know your window size.

Edit Text view increase its size when inserted long text in android

I have edittext view in my application but when i insert long text in edit text this increases view size.I do not want happened in my app because it created bad imapact on app so I decided to use
android:singleLine="true"
android:ellipsize="end"
android:maxLine="1"
xml attribute to the edit text but it not worked for me .I don't have any idea how to prevent this from my problem.I did lot of R&D but i am not get satisfactory answer.Here is my Edit Text.
<EditText
android:id="#+id/etaccountholdersname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvaccountholdername"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="#drawable/ic_input_field"
android:hint="Account holder's name"
android:singleLine="true"
/>
Here Is full code of Xml file
<RelativeLayout
android:id="#+id/innerrel1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<TextView
android:id="#+id/tvaccountholdername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/ic_account_holders_name_text"
android:gravity="left" />
<EditText
android:id="#+id/etaccountholdersname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvaccountholdername"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="#drawable/ic_input_field"
android:hint="Account holder's name"
android:singleLine="true"
android:scrollbars="vertical" />
</RelativeLayout>
Please provide some help me to solve this issues.
In your layout design you have "wrap_content" for both parent and children views. Make the parent layout width as static. If you working with multiple screens, use the dimens.xml for the sizes of the views in different screen sizes.
Use either android:layout_weight property or use android:ems="7" it will work for you definetely
do not use
android:ellipsize="end"
its uses for textview
use
android:ems="10" (it limits edittext to show 10 charecters but you can insert many characters)
and you are good to go.

Truncating a TextView on an AppWidget layout's

people!
Well, after googling for almost two days with no result, I decided to ask here. (It's my first question.)
I'm creating a quotes widget for Android (that shows a random quote each time), so it has two TextViews and a ImageButton to get a new random quote. The first TextView shows the quote text and the second shows the quote's author. And, when the user clicks on the widget, it calls a Activity showing the quote in full screen, with scroll bars if it is needed, and so on.
The thing is that the quote's text sometimes is much long, so I was wanting to ellipsize it. But since the ellipsize doesn't work with more than 2 lines... I'm looking for ideas.
I don't know if it's necessary, but here is the layout code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/laySmall"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="#dimen/widget_margin"
android:background="#drawable/widgetback" >
<ImageButton
android:id="#+id/ibtNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:background="#null"
android:contentDescription="#string/app_name"
android:src="#drawable/seta" />
<TextView
android:id="#+id/txtWdgQuote"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/ibtNext"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="8dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="italic"
android:typeface="serif"
android:maxLines="3" />
<TextView
android:id="#+id/txtWdgAuthor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="bold" />
</RelativeLayout>
Basically, I have 3 AppWidgets in this project, showing almost the same thing. All that change are the sizes and font sizes.
So... One idea that I had was using a custom TextView. But in a AppWidget, no way. :/
Another idea was doing something like this:
if (quoteText.length() > something) {
quoteText = quoteText.substring(0, something) + "\"[...]"
}
The problem of this solution is where is the line breaks, because it can change the size of the string that can be showed. For example, let say a string with small words: the lines will break next to the border. Meanwhile a string that has bigger words the line breaks will be further from the border.
So... I don't know what I do. Any ideas, please?
Thanks!
(I'm having problems with the android:layout_margin, so it can be a little smaller, but I didn't have time to work on this yet.

Android: how to align two text views based on length of text

I have a layout in which two TextViews are to be displayed on the same line such that
If TextView1 is a short text, TextView2 should be immediately right to TextView1(IMAGE1) and if the TextView1 is a long text, TextView2 should be at right corner of the Layout on the same line(IMAGE2)
How can I achieve this ?
i use simple horizontal LinearLayout with android:layout_weight attribute and it worked like you want.
Example:
<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/text1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="teeeeeeeext1"/>
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text2"/>
</LinearLayout>
Use a layout like this..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="38dp"
android:layout_toRightOf="#+id/editText1" />
</RelativeLayout>
edittext 1 will push edittext2 to its right...depending on text in it..
You can set android:maxWidth property for first text view. So your layout would look like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="200dp"
android:text="sdfksdofsdfsdfsdfsadfgwagrswargweqrgeqrgqwergeqrgeqrg"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textView1"
android:text="text2"
/>
Edit:
I apparently misread (or did not read fully) your question. Just don't mind my answer - I vote for mxy's :)
The last time I had the same problem, I wasn't able to find or hack away a straightforward solution. Counting pixels was not an option (at least not for me). But I found a workaround that eventually led to the same display concept, and that was to use SpannableStringBuilder.
As I'm assuming you want two different TextViews because you want them to have different colors (or size, or style, or typeface).
The idea is to use a single TextView for the whole thing, and prepare a SpannableString before doing setText on your view.
By using combinations of ForegroundColorSpan, TextAppearanceSpan, etc, you can make your single TextView look like different TextViews with different styles, sitting side by side, wrapping to the next line as necessary.
Links:
Setting font color at runtime
TextAppearanceSpan sample

Android Textview Italic and wrap_contents

I am using 3 italic textviews with different colors
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:id="#+id/submittedBy" android:paddingTop="10dip">
<ImageView android:id="#+id/subByImg"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="left" android:layout_gravity="bottom" android:src="#drawable/submitted_by_arrow"/>
<TextView android:id="#+id/submitLabel"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="left" android:text="Submitted by" android:textStyle="italic"
android:textSize="12sp" android:textColor="#color/gray" android:paddingLeft="5dip"/>
<TextView android:id="#+id/submitName" android:textStyle="italic"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="12sp" android:textColor="#color/maroon_dark" android:paddingLeft="10dip"/>
<TextView android:id="#+id/submitByDate" android:textStyle="italic"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="left"
android:textSize="12sp" android:textColor="#color/gray" android:paddingLeft="10dip"/>
</LinearLayout>
I wonder every last character is not displaying properly specially name displayed in the middle is "Dan Buckland" and it it is missing last character looks like "Dan Bucklano"
Also tell me pls how can have textview italic and bold both..
alt text http://www.freeimagehosting.net/uploads/953d573113.jpg
I had the exact same problem. I got around it by simply adding a space to the end of any string that needs to be in italics.
It may not be the most long-term-correct solution but it worked for me.
Seems like the bounding box is not correctly calculated when using italic.
Have you tried to use paddingLeft=6 and paddingRight=6 for the elements?
(less chance of overlap).
For multiple styles in a TextView see Is it possible to have multiple styles inside a TextView?
You can use   with the text in string.xml file.

Categories

Resources