Well, i took a TextView inside HorizontalScrollView to scroll the text if it gets too large. But unfortunately, the text isn't aligning properly- form left a lot of text gets hidden if the text is large.
Layout:
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/retBal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Amount is being processed.."
android:textColor="#color/_2ndGray"
android:textSize="17sp"
android:textStyle="bold" />
</HorizontalScrollView>
In activity class:
TextView txtVwRetBal = (TextView)findViewById(R.id.retBal);
txtVwRetBal.setText("Balance is xyz11111111122222222222222333333333444444444555555555666666666677777777788888pqr");
How to solve it?
Why do you need to use horizontal scroll outside? Just add a horizontal scrollbar in your textview- as #Vishwajit Palankar said. Additionally add the android:ellipsize="none" and android:singleLine="true" in your xml layout file.
eg:
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="none"
android:scrollbars="horizontal"
android:singleLine="true" />
and in java file initiate the TextView and add the scrollingMovementMethod()
TextView txtv = (TextView)findViewById(R.id.txt1);
txtv.setMovementMethod(new ScrollingMovementMethod());
txtv.setText("balance is : " + "mnp111111111111122222222222222222222333333333333333333333333333xyz ");
Instead of using HorizontalScrollView you can just set a property in your TextView to make it scroll horizontally
android:scrollbars = "horizontal"
Then in your java class do this
textView.setMovementMethod(new ScrollingMovementMethod());
Related
How to make single line TextView appears if the screen small?, Because it's makes 3 dots of ellipsize without defining it in XML and the rest of text disappeared.
Example:
Please add:
android:singleLine="false"
OR
android:inputType="textMultiLine"
to your TextView
EDIT:
Your TextView can look something like this:
<TextView
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/your_text"
android:maxLines = "1"
android:scrollbars = "vertical"/>
and add these two lines to your onCreate
TextView yourTextView = (TextView) findViewById(R.id.test);
yourTextView.setMovementMethod(new ScrollingMovementMethod());
Not too clean but does the job.
SECOND EDIT:
<TextView
android:text="#string/yourText"
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever" <!-- Please change according to requirement -->
android:scrollHorizontally="true"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true"/>
Hope this helps!
I have a TextView that when it has a long text, it resizes to make the text fit inside, breaking the UI.
Is there a way to use a XML attribute to make the TextView not resizable?
I was thinking about using the TextView inside a ScrollView, is there other options?
For this to work, set specific width to textview (It will display textview without scroll)
android:layout_width=""
If you want to show scroll, add scrollview with specific size and inside scroll layout, add textview like
<ScrollView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/scrollView"
android:fillViewport="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
100dp is dummy size here.
Solution :
<TextView
android:elipsize="marquee"
</TextView>
check out this Answer for more options :
Elipsize Examples
this will slide the textView
Try this code:
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:singleLine="false"
android:singleLine="false"
android:text="Long multiline text"/>
I need to right align my text in a TextView like this.
How to achieve this?
Below is my layout.xml file's textview
<TextView
android:id="#+id/sampleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/dummyTextView"
android:layout_alignLeft="#+id/dummyTextView"
android:gravity="right" />
Did you try?
<TextView
android:id="#+id/txtItemDay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical|right"
android:text="Your text"
android:textColor="#android:color/white"
android:textSize="22sp" />
The problem is:
android:layout_width="wrap_content"
You could not align text in TextView if you set with is wrap_content, please set fill_parent or match_parent or specified witdh.
You're using android:layout_width="wrap_content" which means its not able to set the gravity because you don't have enough space for the text to align. Try using this instead:
android:layout_width="fill_parent"
I have TextView that automatically scroll left-to-right when input text doesn't fit into it.
Now I need to add the ability to scroll horizontally through the hands of the text in TextView when the text does not fit into it - so the user can view the contents of TextView.
I add TextView to HorizontalScrollView:
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/btnBackspace"
android:layout_toRightOf="#+id/textViewLeftIndent"
android:fillViewport="true" >
<TextView
android:id="#+id/calculateField"
android:layout_width="534dp"
android:layout_height="wrap_content"
android:background="#color/lightgray"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_vertical|right"
android:inputType="textImeMultiLine"
android:overScrollMode="ifContentScrolls"
android:scrollHorizontally="true"
android:text=""
android:textSize="80sp" >
</TextView>
</HorizontalScrollView>
But now I have editable through the virtual keyboard TextView and cannot scroll full text, only part of it (when text's big).
Add this to your TextView widget
android:ellipsize="marquee"
and check if it works now
update
It it not works add this
android:singleLine=”true”
I have a some ui widgets including textview inside RelativeLayout which is clickable. My problem is textview text color does not change when relativelayout gets focus although I have set textview color property correctly.
Is there any easy way to cascade focus to childview inside relative layout, same as listview items.
<RelativeLayout
android:id="#+id/top_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/selector_white_blue"
>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:textSize="#dimen/text_size_med"
android:textColor="#color/black_text_white_focused"
android:textStyle="bold"
android:text="Movie Name"
/>
</RelativeLayout>
Specify android:duplicateParentState='true' on your TextView.
Programmatically by textView.setDuplicateParentStateEnabled(true);
for your
TextView textView= new TextView(this);