Edittext how to move chars to the left if filled - android

I have an edittext which has a width depending on another view on its top which is a textview. I set both the views to wrap content so that the edittext will copy the textview's width. But, when the edittext is completely filled up, the characters make a new line. How can I make it such that when the edittext is completely filled up the characters are only moving to the left. If possible, I do not want to hardcode the width. Is there any solution for this? Thanks.

Add this to your EditText XML:
android:singleLine="true"
android:maxLines="1"

android:singleLine="true" only

Related

Hide a partially visible line in a text view (Android)?

I have a textview with fixed height that contains text downloaded from a server. Sometimes the text is more than the view can wrap and it is cutting the extra text. The problem is that the last line the view can show is only partially visible which is kind of ugly.
Is there a way not to show a line if it is only partially visible?
android:maxLines wont help, because my layout has two textviews with different font sizes.
You can make textview scrollable. Add these lines :
android:maxLines = 'int' // put any integer value.
android:scrollbars = "vertical"
You can use android:ellipsize
android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
https://developer.android.com/reference/android/widget/TextView.html#attr_android:ellipsize
Try this one:
android:elegantTextHeight="true"

Align the start of the text in EditText and TextVIew

I have a simple layout in a table that consists of 3 rows. The second column may have either an EditText or a TextView like in the picture below:
Now, my question is how can I align the start of the text in EditText and TextView so that they are visually under each other (the texts, not the controls)? In the image above, the text in the second line starts too much to the left. I don't want to hardcode the padding as it may not work the same way on different devices.
try setting a padding for the second textview.
android:padding="5dp"
Instead of making the TextView match the EditText, make the EditText match the TextView by making its background null:
<EditText ... android:background="#null" ... />
The underline in the EditText then goes away and everything lines up perfectly.

How to keep EditText from breaking to the next line when width does not match_parent?

I am trying to fit two EditTexts horizontally. What I am trying to accomplish is make the text keep scrolling right without the EditText extending in anyway when there is no more space in that specific EditText. This happens when the EditText is set to match_parent (width), but when I set an actually width or wrap_content, it breaks to the next line. Not the behavior I am hoping for. Any ideas?
If I understood your question correctly, you're saying you want the edit text to be a single line each? If so, have you tried using the xml attribute
android:singleLine
Or you can accomplish the same thing with:
setSingleLine() //called on the edit text
I just tested it out with 2 edit texts in a horizontal linear layout set to 100dp width each and I think it accomplishes the behavior you want.
You can try this:
Set both to fill_parent and layout_weight=1. This will align them side by side.

How to properly align form?

I have a form with a format of:
<LinearLayout>
<RelativeLayout>TextView EditText Button</RelativeLayout>
<RelativeLayout>TextView EditText Button</RelativeLayout>
<RelativeLayout>TextView EditText Button</RelativeLayout>
<RelativeLayout>TextView EditText Button</RelativeLayout>
</LinearLayout>
I have aligned the TextView to parentLeft, the Button to parentRight. And so far, the EditText to toLeftOf Button. Now, I want the EditText to all line up with the longest TextView, however I can't seem to use toRightOf of a TextView from a different layout. I'm not even sure that's the best way to do it.
What is the proper way to get everything to line up straight?
Consider using TableLayout instead
You can try replacing the LinearLayout with RelativeLayoutand and remove the RelativeLayout for each row or use TableLayout as asahi suggested.

How to set a long string in a text view in a single line with horizontal scroll

actually i have keep one scrollview. Inside that scroll view I set one textview at run time I want to set text in that textview. The string which I'm going to set is some what big in length so i could not get the string in a single line and i can get my string two or three lines. My scroll view layout width size is 250px. I dont want to exceed that size...My expectation is i want to see that string within that scrollview as single line if the string is exceeds the scroll size then it should horizontally scroll in text view. I tried some functions like setting horizontal scroll to scrollview and textview but nothing is work out.
Pls help me how to solve this problem.
urs,
s.kumaran.
you have to use these two Xml attributes in your TextView widget:
android:scrollHorizontally="true"
android:singleLine="true"
So your xml layout must contain something like this:
<TextView
android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
you can get the correspondant method for these attributes if you are creating Your TextView with code, refer to TextView documentation :
setHorizontallyScrolling(boolean)
setTransformationMethod(TransformationMethod)
setMarqueeRepeatLimit(int)
try this ,,
TextView.setHorizontallyScrolling(true)
TextView.setLines(1);
where did you add the textview..Inside scrollview we able to add only one view...
Take TextView and HorizontalScrollView. Just put textview inside the HorizontalScrollView. And yes make sure to mentioned android:singleLine="true" inside the TextView.
I had the same issue with a TextView inside a table and nothing detailed here solved the fact that it wouldn't scroll horizontally (automatically, which might not be the desired effect from OP, but it's quite unclear).
While comparing some code that did work, I found out the TextView must be selected for scrolling to start:
TextView text_view = new TextView(context);
text_view.setLines(1);
text_view.setHorizontallyScrolling(true);
text_view.setMarqueeRepeatLimit(-1); // At this point the view is not scrolling!
...
text_view.setSelected(true); // Get scrolling to start
Seems crazy, but it works.
for me, this one line in the EditText xml was enough:
android:singleLine="true"
You didn't specify if this was in XML or java code, but here's the java code to get that working:
// Allow textView to scroll
textView.setSingleLine(true);
textView.setHorizontallyScrolling(true);
textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
textView.setMarqueeRepeatLimit(-1);
textView.setSelected(true);
textView.setPadding(10, 0, 10, 0);
The only unnecessary item here is the padding, which I find to look best so the text does not touch the border of our 250px TextView.

Categories

Resources