TextView drawableStart wrap_content doesn't work well - android

I want to display a textview with a compound drawable which wraps the content - the shape and the text. Here is my code:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text_category_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:drawableStart="#drawable/shape_circle"
android:drawablePadding="10dp"
android:padding="10dp"
android:textSize="16sp" />
drawableLeft works fine, it wraps the shape and and text, no problem. But drawableStart (and so I assume drawableEnd) seems to wrap the text, THEN add the image, and as such trim the text, so it looks like this:
I've tried removing the drawablePadding, padding, layout_marginStart - these don't have an effect on the text still being trimmed.
Is there a non-hacky way to fix this? I don't want to have to set a specific width, and I do want to use drawableStart and not drawableLeft if possible. I've had a look for existing answers, and all I can find so far is that it is a quirk of the RTL nature of drawableStart/End, but I can't see a clean solution.

Related

Ho to Create text View with skew pattern with out adding \t of \n?

I want to create text view different margin starts for different lines(Line skew pattern) with out\t of \n. for example:
Your best bet would be to use either padding or margin and maybe look at separating the texts into separate Textviews to achieve this...
Example:
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:paddingLeft="10dp" <!--either margin or padding -->
android:text="Stackoverflow..." />
I've seen other answers regarding the use of Webviewsand using text set to HTML to display in the Webview.
Could work potentially.

Android - 9patch padding on a Button

I created a button with a 9patch image as a background. In the 9patch image I used the bottom and right lines to specify the content area/padding, to position the text on the button. This works well on a TextView, but on a Button the content lines seem to have no effect on the text position. Setting "paddingTop"/"paddingBottom" also seem to have no effect - only "padding" has any effect.
This is my layout XML:
<Button
android:layout_width="450dp"
android:layout_height="198dp"
android:text="Some text here"
android:gravity="center"
android:background="#drawable/my_button"/>
Is there any way to set the padding? Maybe I could use a different View instead of a Button? For example, I could try to just use a TextView and make it clickable, but I'm not sure what other side-effects this will have.
Explicitly setting android:padding="#null" solved my issue.
The issue seemed to be that a Button (or one of the styles in the theme I'm using) is setting the padding, which overrides all other padding in the button - padding in the background drawable, as well as paddingTop, paddingLeft etc.
My button layout is now defined like this:
<Button
android:layout_width="450dp"
android:layout_height="198dp"
android:text="Some text here"
android:gravity="center"
android:padding="#null"
android:background="#drawable/my_button"/>
My IDE (IntelliJ IDEA 11.1) picked up the #null as an error, even though it compiled. Setting it to -1px also worked.
If you use a 9-patch image as background, both the padding and the stretched areas are defined in the background.
It's quite graphic if you use the draw9patch tool: the padding is defined (indirectly) with the content area (lines on right and bottom):
http://developer.android.com/guide/developing/tools/draw9patch.html

Android: EditText content

)
I am having a bit of a problem with my app. I am using a multiline edit text.
I want its content to have a bit of a left space (not the edittext, but the text in it), because of a drawable i set as backgroud for the edittext.
Just like padding works for layout alignment, is there anything to align text?
Try:
<EditText
.....
android:paddingLeft="50dp"
.....
/>
If you want to have a padding,
You can simply use android:paddingLeft="20dp"
or android:padding="20dp" for your EditText in your XML.(i don't know exactly what you want, just try).
If you want to align your text,
Try to use Android:Gravity in order to align your text in your EditText.
Here is the code : android:gravity="right" (in order to have right align for your text)
You can find more information about what you can do with this here : Android Gravity

Set ImageButton text from the code?

In examples found on the net I saw that the text is set from XML file only. I need to attach the text from another View, and I tried to find any setter that I can use to set text to ImageButton. I didn't succeed. I even tried using this
<ImageButton
android:background="#ffffff"
android:text="setText()"
/>
hoping that I can use setText() in the code, but it did not work as well.
How can I set the text for ImageButton programmatically?
Thanks
PS. This is a custom ImageView which inherits ImageView.
ImageButtons can't have text (or, at least, android:text isn't listed in its attributes). It looks like you need to use Button (and look at drawableTop or setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)).
You cannot set text to ImageButton because it has no method as setText() or android:text property.
Here is workaround, using a Button and android:drawableTop / Left / Right or Bottom like this :
<Button android:layout_height="wrap_content"
android:drawableTop="#drawable/icon" android:text="Button"
android:layout_weight="1" android:layout_width="fill_parent"
android:textSize="11sp"
android:layout_margin="1sp" />

android button fine text alignment

I'm trying to create standard button in android with a background and some text in front but some fairly specific alignment. I want the text to be centered vertically and on the left with 20dp of padding. The alignment works but the padding doesn't. I know I could probably get the desired effect by putting a few spaces in the text but that seems like a hack and next I want to do a similar thing but with the text at the top so I would prefer a more elegant solution.
Here's what I have:
<Button
android:layout_width="312dp"
android:layout_height="95dp"
android:id="#+id/gv_music_button"
android:text="Music"
android:textSize="30sp"
android:paddingLeft="20dp"
android:gravity="left|center_vertical"
/>
My mistake, padding was working correctly. Just didn't appear to be.

Categories

Resources