I've got an EditText...
<EditText android:id="#+id/box" android:autoText="true"
android:layout_width="fill_parent" android:layout_height="45dip"
android:singleLine="true" android:hint="Enter" />
Is it possible to make the text only appear up on till say... 50dip from the end of the EditText?
So when typing a query it'd look like
____________________
|y query is cool |
--------------------
while typing my query is cool
You can use paddingRight in this case (assuming I understood you correctly). Here is an example:
<EditText android:id="#+id/box"
android:autoText="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="50dp"
android:singleLine="true"
android:hint="Enter"
android:text="1234567890ABCDEF-1234567890ABCDEF"/>
The best alternative is to create your own nine-patch file and decide exactly how much padding you want.
See my answer here for a quick intro: How to create android spinner without down triangle on the right side of the widget
and the official docs here:
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
http://developer.android.com/guide/developing/tools/draw9patch.html
Then, you should use
android:gravity="right"
inside your EditText
im a little confused also as to what you were going for, my first thought would be to add
<EditText android:id="#+id/box"
android:autoText="true"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:singleLine="true"
android:ellipsize="start"
android:hint="Enter" />
but maybe that wasn't what you meant? you could use this in combination with the techniques listed about so that the user wouldn't be confused by the missing characters.
Related
I am using GridLayout from the support Library. Some of the cells contain player information - I use a Linear Layout with two TextViews. I have not been able to get the name (the second text view) to wrap.
Current behavior:
123
John Cochtousczyon
Desired behavior:
123
John
Cochtousczyon
Here's the current state of the cell layout xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/player_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="test" />
<TextView
android:id="#+id/player_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:minLines="2"
android:scrollHorizontally="false"
android:text="testing thisout with extra sauce"
android:textSize="18sp" />
</LinearLayout>
and the code that adds him to the grid:
lp = (GridLayout.LayoutParams) playerCell.getLayoutParams();
lp.columnSpec = GridLayout.spec(nameCol);
lp.rowSpec = GridLayout.spec(nameRow);
playerGrid.addView(playerCell, lp);
Ideally I would like a solution that sets the column width for the widest cell AFTER wrapping the name. I've gotten close to the desired result using maxEms, but that requires balancing the most likely needed limit against how much truncation to tolerate with longer names.
P'r'aps there's nothing for it but to fix the width - just thought I'd ask in case all the smarter people than me out there have solved this.
Here's what I've settled on for now, until something better comes along:
<TextView
android:id="#+id/player_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxEms="4"
android:maxLines="2"
android:text="testing thisout with extra sauce"
android:textSize="18sp" />
combination of fill_parent, ellipsize END, maxEms and maxLines gets me close enough.
If anyone is still looking this in 2020 Android now has a inbuilt way of doing this. Just add this code to your java file
TextviewCompat.setAutoSizeTypeWithDefaults(<your textview refernce here>, TextviewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
Also make sure you add this to your textview xml
android:ellipsize="none"
Hopefully this will help someone;
I simply used the good old "\n" to wrap.
I want to make a multi line edit text but the problem is that whenever i enter new line height of edit text increases. how to fix its height. My code is
<EditText
android:id="#+id/editAdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignParentBottom="true"
android:layout_marginBottom="60dp"
android:layout_below="#+id/editPhoneCutomerDetails"
android:layout_marginTop="10dp"
android:background="#drawable/message_additional_box1x"
android:ems="10"
android:padding="10dp"
android:gravity="top">
<requestFocus />
</EditText>
To fix the size of editText you can use
android:singleLine="true"
but it can limit your editText line to 1 .
if you want more lines in editText then use the following property.
Use android:lines="3" .
Use android:lines="2" for fixing multilines and for fixing single line use android:singleLine="true"
for example use like this as shown for multilines
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:lines="2"// fix the multiline limit
android:textColor="#000000" />
for example use like this as shown for single line
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:singleLine="true"// fix the single line limit
android:textColor="#000000" />
try this;
android:inputType="textMultiLine"
<EditText
android:inputType="textMultiLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
As singleline is now deprecated use inputType:multiline and set the number of lines you want with lines tag
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="4"/>
I had a similar requirement but ended up not changing the size of the box. i.e it grows as text is typed into it but stops short of blocking the other widgets in view. I read this post during my quest and had found a solution. Decided to post it back here. Restricting size to a value may possibly have different effects on different screens. So I think it is better to let it be.
The thing is to put the edit text inside a linearlayout with the rest of the widgets. The code and snapshot are here
Multi line edit box with ok cancel buttons
I know this question has been asked a number of times but I still can't seem to get this to work.
I have tried all sorts of combinations and it just refuses to wrap to 2 lines.
This is what it is now:
<TextView
android:id="#+id/doctor_details_clinic_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="3dip"
android:textSize="12sp"
android:maxLines="1"
android:layout_gravity="right"
android:gravity="right"
android:scrollHorizontally="false"
android:singleLine="false"
android:ellipsize="none"
/>
I've tried make the width 0dip and all other things suggested but to no accord.
First of all you should set Max lines to 2 instead of 1.
Something like this will work:
<TextView
android:id="#+id/myText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:ellipsize="end"
android:text="this is the most interesting use of text view I have seen so far,this is the most interesting use of text view I have ever seen so far,this is the most interesting use of text view I have ever seen so far this is the most interesting use of text view I have ever seen so far"/>
I have a log In page with username and password fields. I would like to know the best place to put the log-in button below them. Should it be left-aligned, centered, right-aligned or fill the entire width of the parent?
Is there a industry standard or best practice for Android Log In Buttons?
An idea would be to align them below the edit text views that will be completed. That's the most elegant way to do it.
You can try something like this
Or maybe something like this one
I would say put the login button below the fields. And center it, filling the same amount of space as the fields. This would look the best and would show up great in landscape and portrait.
A lot of companies put a lot of research into the best UI layouts.
The basic layout for login activity that I stumble upon everywhere in a books looks like this:
<TextView android:id="#+id/userNameLbl"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Username: "
android:layout_alignParentTop="true" />
<EditText android:id="#+id/userNameText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#id/userNameLbl" />
<TextView android:id="#+id/pwdLbl"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#id/userNameText"
android:text="Password: " />
<EditText android:id="#+id/pwdText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#id/pwdLbl" />
<Button android:id="#+id/btn" android:onClick="doClick"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Login" />
So it's pretty much similar to what #Arkde tried to show you in the second link.
Hope this helps.
I am currently writing an App for Android and in one of the layouts I have a users name and beside it a couple of tags.
If both the users name and the tags are short enough, they fit neatly into one line. However, when either of the two are longer I want the name to stay fixed to the left, and the tags to drop to a line below and align to the right.
Currently I have the following code:
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/name"
android:textColor="#000000"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:singleLine="true"
android:id="#+id/tags"
android:textColor="#000000"
android:layout_toRightOf="#+id/name"
android:layout_alignTop="#+id/name"
android:textAppearance="?android:attr/textAppearanceSmall" />
This just simply displays both on one line. I presume I'll need to do the text wrapping in the java or is there a neat XML solution?
As far as I know, there is no XML solution for this problem.
You need to calculate the size of the name and then adjust the tag on the new line or keep it at same line.