I have a button which shall look like
[1 44.33]
so that the text is aligned to left and right at the same time.
Is it possible to achieve it with a single element, w/o introducing nested TextViews?
You can set ellipsize to middle and set singleLine to true for Button.
<Button
android:id="#+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="so that the text is aligned to left and right at the same time.Is it possible to achieve it with a single element, w/o introducing nested TextViews?"
android:textColor="#888686"
android:ellipsize="middle"
android:singleLine="true"
android:textSize="15dp" />
Yes, you can check the ellipsize element in Button Tag.
Related
I have a problem with my project. I use android.widget.Button. When word can not fit in one line in the Button then it cut it like this: Somelon>gword (where '>' is new line). How to fix it? And how to create inner padding for the text because the long word touches the button's borders?
You can try below code. Where paddingRight and paddingLeft keep padding of 25dp in right and left. If you want to text on in one line.Then
you can use android:singleLine="true"
<Button
android:id="#+id/she_was_good"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="25dp"
android:paddingLeft="25dp"
android:ellipsize=”marquee”
android:text="#string/im_sorry_lol_str" />
Read this post
Try using the property android:singleLine="true" and android:padding="10dp" to your button widget.
Is there any way to center the inputted text in an EditText field? More specifically, instead of the cursor starting at the left of the box, it should start in the center and move outward towards the left as it is populated with inputs.
you should use
textView.setGravity(Gravity.CENTER_HORIZONTAL);
Try android:gravity="center_horizontal" in the widget definition in your layout file. This will not strictly "move outward towards the left" -- it should move outward in both directions evenly. If you truly mean you want the text to only be on the left side of the EditText, I doubt that will be possible.
Simpler Solution to align text in EditText is to add android:gravity="center" in layout xml. There is no need to add Java code.
Tested Sample Code-
<EditText
android:id="#+id/FieldName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:inputType="numberDecimal"
android:gravity="center" />
In edittext the text is coming leftmost corner. but i want to display the text after one space . so it should be more readable.
Any one can help me in this problem.which tag in edit text i have to use.
Try providing margins around your EditText Background like this,
<EditText android:id="#+id/tickets_value"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dip"
/>
You can use either the padding or the margin element of the view.
While margin offsets the entire view the padding offsets the content within the view.
http://developer.android.com/reference/android/view/View.html
I am trying to port my WP7 app to android.
Does anyone know how I can layout the text on a single button so that some text appears aligned left and other text appears aligned right? (See below). I need access to be able to dynamically change the percentage number on the right side using code but the text on the right is just static.
Anyone know the answer to this?
The image is here:
http://i.imgur.com/zW7YV.png
Yes you could make it two buttons.
Remove all padding and margin from between them.
Set the same background drawable.
And just ensure when the left is clicked it invokes the right's onPress method (so it looks as if they depress together).
Or wrap the buttons/imageviews/textviews in a layout and perform the onClick on that.
I would use a RelativeLayout for this.
<RelativeLayout
android:width="fill_parent"
android:height="wrap_content"
android:clickable="true"
android:background="#18a2e7"
android:padding="10dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Something" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_align_parentRight="true"
android:text="0%" />
</RelativeLayout>
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.