I have seen many similar questions to this one but I think this still covers new ground:
1) Hint text disappears when you set gravity
2) android:ellipsize="start" fixes that so you can have centered hints and centered text
3) why does the code below still show centered hint text?
<EditText
android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="use this area to provide specific identification information including approximate size, vessel name and registration numbers if available"
android:background="#android:drawable/editbox_background"
android:layout_below="#id/details_title"
/>
is it because of fill_parent instead of wrap_content? i thought maybe it was because this hint is multiline, but i shortened it and it still appeared and was centered. those are the only differences between this and my other EditTexts that needed android:ellipsize="start" to display correctly. is it just a bug?
You need to use android:gravity="top" instead of center in order to have your hint and your text start at the top left of the box.
add this attribute to your EditText
android:ellipsize="start"
It just works
<EditText
android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:ellipsize="start"
android:hint="use this area to provide........"
android:background="#android:drawable/editbox_background"
android:layout_below="#id/details_title"
/>
Related
I am trying to create a RadioButton in android. My requirement is that the label should be always left aligned and icon should be right aligned(evenly distributed, as first item in attached screenshot). I was able to achieve it. But this is not working when the label has no character and only digits between 0 to 9.
I also tried adding space, but no luck.
Can someone please help?
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listRadioItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:ellipsize="end"
android:layoutDirection="rtl"
android:maxLines="1"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:text="123"
android:layout_gravity="start"
android:textAlignment="textStart" />
I think the easiest solution, if you know it always needs to be left-aligned, is to use
android:layoutDirection="rtl"
android:gravity="center_vertical|left"
Otherwise it might be worth looking into formatting for RTL text because I think the handling of numbers is what's causing that behaviour, where "start" and "end" become flipped (because you don't necessarily want to reverse a number, so it might be treated as LTR - I'm not an expert on any of this though!)
I have used EditText in my application, the problem is the entered text is not aligned properly, check it out my screen shot for what exactly my issue is.
My EditText XML file is
<EditText
android:id="#+id/signupFullName"
android:layout_width="179dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/updatedprofieledit"
android:ems="10"
android:hint="#string/enterfullanme"
android:inputType="textPersonName"
android:paddingLeft="10dip"
android:singleLine="true" >
<requestFocus />
</EditText>
Kindly help me to clear this issue, have tried with some EditText Specification but no luck.
Thanks
It appears that your background image is smaller than your hard-coded width. Adding padding reserves some "unused room" at the end of your EditText. It would be better if you converted your background image to a 9-patch image so that it could resize automatically.
add this line into your edit text
android:padding="5dp"
use this
android:paddingRight="10dip"
I have a TextView which has a height of 30px and a textsize of 40px. Since the text is taller than the View, I only want to display the middle part of the text.Like this:
But with android:gravity="center_vertical", I only can display the upper part of the text with some bottom part cut off.
And this is my code:
<TextView
android:layout_width="wrap_content"
android:layout_height="30px"
android:textSize="40px"
android:text="ABCDEFG"
android:gravity="center_vertical"
/>
Anyone knows of any way to do that? Thanks!
Can't you simply wrap it in a LinearView set to the appropriate size and adjust the margin within the textview to about half (depending on padding) the font size?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="#android:color/white">
<TextView
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="Sliced in half"
android:textSize="60dp"
android:layout_marginTop="-30dp"/>
</LinearLayout>
Resulting in:
http://i.stack.imgur.com/jEdxx.png
I highly doubt whether you can do that. All the options that I have come across while dealing with TextView are for when the Text is smaller than the View. This is the first question that I have come across which has the requirement otherwise.
One option which I had used before was android:scrollHorizontally="true" where in you specify whether the text is allowed to be wider than the View.
Interesting question. It would be great if you could add some code though.
I am currently developing an electronic guide for Latvian traveler. I have a scrollable 'textview' which is going to show information about object which is selected. So the problem is when i touch the text and start to scroll it is looking like this good
but when i touch it a little longer it turns black and after i scroll it for three lines text color is white again.bad
So the question is how to make it stay white on longpress or where the problem could be?
My textviews code:
<TextView
android:id="#+id/textView2"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_below="#+id/imageView1"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:maxLines="5"
android:scrollbars = "vertical"
android:background="#drawable/rect"
android:text="Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
I just came across this issue, so maybe someone will make use of this answer:
Define the TextView color attribute explicitly to white and it won't change in touch events.
I have an EditText and a Button set next to each other on the same horizontal line. It looks great, except when the user enters a lot of text, the EditText is resized, and the Button is squished.
I have both EditText and Button set to layout_width="wrap_content". "fill_parent" messes up the layout, and I don't want to use absolute sizes if I don't have to - the way it is now looks great in both landscape and portrait, I just don't want the EditText to resize.
My layout:
<TableLayout
android:id="#+id/homelayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow>
<TextView
android:id="#+id/labelartist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Find artists:" />
</TableRow>
<TableRow>
<EditText
android:id="#+id/entryartist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="6"
android:background="#android:drawable/editbox_background"
android:editable="true"
android:padding="5px"
android:singleLine="true" />
<Button
android:id="#+id/okartist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:layout_weight="1"
android:text="Search" />
</TableRow>
</TableLayout>
For EditText use
android:layout_width="0dp" - not required but preferred.
android:layout_weight="1"
And for Button dont specify android:layout_weight
What I do is in the onCreate for the activity, measure the EditText first then apply its maxWidth.
You can do so using code similar to the following:
EditText someedittext = (EditText)findViewById(R.id.sometextview);
someedittext.setMaxWidth(someedittext.getWidth());
Give EditText a maxWidth. That should stop it from resizing beyond the width you provided. Also, if you want it to be contained within 1 line set the maxLines setting to 1 too.
You need to add android:imeOptions to prevent this behavior.
Just use:
android:layout_width="fill_parent"
for both EditText and Button. It will also work set for EditText but it is better to have it on both.
you can define size of your edittext as it shows above
android:minWidth="80dp"
android:maxWidth="80dp"
or
android:layout_width="60dp"
or
you can apply a background image of size you want
but don't forget to define its height and width
with wrap_content.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
I had a similar problem, but I couldn't get the above to work. What I did, is take in the text from EditText box and then format it down to the max size that my screen could handle. When I save this off to the DB, I will save it as display Text and original text.
If you go to this page I put a longer explanation.
The correct way to do this would be to set the android:minWidth and android:maxWidth equal to the width you want. This way you will not have to adjust your layout to use the android:layout_weight.
For example if you want your EditText to always be 80 density pixels no matter how many characters you type in use the following:
android:minWidth="80dp"
android:maxWidth="80dp"
I had the exact query. But i had an EditText and a Button next to each other in a Linear Layout.
I tried android:layout_weight="1" for EditText
android:layout_width="0dp"
And it worked just perfect!!
Thanks a lot!
The chosen solution works, but let me add a little complement:
if you use
android:layout_weight="0.15" (the value is not important)
then
android:layout_width="0dp" if the LinearLayout is Horizontal
or
android:layout_height="0dp" if the LinearLayout is Vertical.