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
Related
I have a multiline EditText, for editing Arabic text, as you can see Android cuts off some characters because they are rendered right after zero margin (adding spaces is not a solution because it's multi-line and the user changes the text by editing, adding padding and margin is not a fix too):
Did you try to add padding correctly?
You may try this:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
paddingLeft and paddingRight make sures that it leaves 10dp size left and right of your text inside your EditText.
Also you can may add some attributes to this EditText that I think it would be great:
android:gravity="center"
android:textDirection="rtl"
gravity="center" would make the text be centered at the center of the EditText (You may like this approach but it shouldn't be necessary to fix the above problem).
textDirection="rtl" make sures that this language is from right to left so it would be more professional to make it.
You may also try this instead of paddingLeft and paddingRight:
android:paddingStart="10dp"
android:paddingEnd="10dp"
I have a layout/alignment problem with a TextView which I haven't yet been able to find a solution for, that is, I want to align text off-center inside a TextView horizontally.
To give a little more context, I have an ImageView and a TextView side by side, the ImageView touching the left edge of the screen and the TextView filling the rest of the screen horizontally, like this:
[-img-|-----text-----]
The TextView is configured as singleLine="true" and maxLines="1", so that it will be truncated if its too long for its horizontal space. My aim is to align the text in the center of the screen, not the center of the TextView, because there are other elements on the screen that are aligned to the center and I need the text aligment to match that.
So, if I use gravity="center" on the TextView, I get the image above, but what I actually want is
[-img-|--text--------]
I tried putting image and text in a RelativeLayout, so that the TextView actually touches both edges of the screen, which does what I want with respect to the alignment, except that if the text is long enough, the first characters will be hidden by the image, since the TextView lies behind the image view.
I also experimented with margins, padding and a compound drawable to the left, but the text is always centered relative to the available space (which I would consider the expected behavior).
Does anybody have any clues on how to achieve this alignment, i.e. relative to the center of a different component than the TextView, maybe programmatically at runtime? Thanks in advance for any helpful advice.
Edit: user Budius suggested using padding to the right to achieve a centered alignment which works but leads to long texts being truncated before the right edge of the TextView is reached and I'm looking for a solution that avoids that, i.e. that uses the entire avilable space, if possible.
I believe that will center it and the move 20dp to the side.
gravity:centre padding:right=20dp
Try using
android:layout_weight="1"
if it helps you..
I know this is not the correct approach than too give it a try..
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".33"
android:gravity="center"
android:text="text" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:src="#drawable/ic_launcher"
android:visibility="invisible" />
)
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
I am creating an Android app, and I have a button with a custom background image behind it. The background image is just a rectangle, but now the button text does not seem to be centered vertically. Here is my xml for the button:
<Button
android:id="#+id/save_to_list"
android:layout_below="#+id/info_pic"
android:text="SAVE TO LIST"
android:textColor="#android:color/white"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_width="260dp"
android:layout_height="35dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"></Button>
and I set the background here:
ImageView button_bg = (ImageView)findViewById(R.id.button_background);
savetolist_button.setBackgroundDrawable(button_bg.getDrawable());
Is there a where to change the position of the text within a button?
android:layout_gravity defines layout alignment inside it's parent. To align text within the button you need android:gravity, for example
<Button
...
android:gravity="center"
...>
</Button>
Your button is too short to fit the text properly. Increase the layout_height and the text should be centered.
Your text likely has some padding built into the font as part of each letter, and that is why your text is being pushed in one direction. Set the layout_height to "wrap_content" and your text should now be centered correctly.
I found it best to use a 9 patch image for a rectangular background rather than an xml drawable.
I have a row of buttons with custom 9 patch images, and variable length text. I would like the buttons to be the same height. When the text is long enough to wrap, it expands the button size, making the button with wrapped text bigger than the others. I'm laying these buttons out in code in linear layouts. I can fix the size of the button, but then it just cuts off the bottom. How can I make the text take up more of the padding space of the button, so that the text butts up against the top line of the button?
9patch content area is just used to set a padding. If you change the button's padding you will override the one set by the 9patch.
edit
try something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:text="ButtonButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingTop="0dp"
android:paddingBottom="10dp"/>
<Button android:layout_width="wrap_content" android:text="Button"
android:layout_height="match_parent"/>
<Button android:layout_width="wrap_content" android:text="Button"
android:layout_height="match_parent"/>
</LinearLayout>
this way the button will be as high as the others. Sadly, I don't know if it depends on the original button's 9patch that might have asymmetrical paddings, but I can't make the text align with that from other buttons (I think gravity is by default set to center). Maybe with your 9patch it works though. (EDIT: oh, but if you'll have two lines of text who cares about alignment)
Ultimately I was unable to find a nice way of doing this without creating a custom view class.