Align the start of the text in EditText and TextVIew - android

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.

Related

Edittext how to move chars to the left if filled

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

Create animation for text field

I need to create an animation in Android. I have 3 TextViews placed in an LinearLayout. All I want to do is the text field must come on to the screen as though it has been pulled out from the left end of the screen. Something similar to a marquee, however the text field must come from left end of screen one character at a time to occupy the left end of screen.
you must textView set textview property in your xml layout android:ellipsize="marquee" and you oncreate() method to set textview like youtextview.setSelected(true); now your textview running with marquee effect perfectly work for me!
another way you can add dynamically textview in coding you can follow this code:
yourtextview.setEllipsize(TruncateAt.MARQUEE);
yourtextview.setSelected(true);

How to put an ellipsis at the end of TextView containing two lines

I have a TextView in Android and I want to put an ellipsis (". . .") at the end of the TextView when there are more characters in the text than the size of the TextView (i.e. when the entire text cannot be displayed in the TextView).
I know the solution when there is one line in the TextView:
singleLine="true" and maxLines="1"
However, I have two lines in my TextView.
android:ellipsize="end" for ...end of text
there is a setEllipsize method on the textview,
which takes a parameter of:
TextUtils.TruncateAt END
TextUtils.TruncateAt MARQUEE
TextUtils.TruncateAt MIDDLE
TextUtils.TruncateAt START

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