Auto show rest of TextView - android

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!

Related

How to fit the TextView text in HorizontalScrollView

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());

Set Image to the left of text in a TextView

Sorry for a noob question, I think it should be done with Spannable or something, but I can't google it right.
I need a text in a TextView with a drawable to the left of each line . How do I do it?
Try this..
By using XML
Use android:drawableLeft="#drawable/ic_launcher" to your TextView
<TextView
android:id="#+id/txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:drawableLeft="#drawable/ic_launcher" />
By using Code
Youe can see setCompoundDrawablesWithIntrinsicBounds
TextView textView = (TextView) findViewById(R.id.txt);
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_launcher, 0, 0, 0);
Try this android:drawableLeft="#drawable/sampleImage" in TextView Tag in XML file.
see this property of TextView
android:drawableLeft="#drawable/yourIcon"
<TextView
android:id="#+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/yourIcon"
android:ems="10"
android:text="TextView" >
<TextView
android:id="#+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Your Text"
android:drawableLeft="#drawable/ic_launcher"
android:padding="10dip" />
you can even use a linearlayout with orientation vertical with one ImageView and Textview in that align textView layout to center

Android TextView text changes color on touch, but it shouldn't

I've encountered a strange problem where I have a TextView that I have made scrollable through XML android:scrollbars="vertical" & programmatically with
.setMovementMethod(new ScrollingMovementMethod());
When I touch the TextView, the white text changes to light gray.
If I remove the .setMovementMethod(new ScrollingMovementMethod()); I don't get that response.
What is causing this and how do I prevent it?
Thanks
<TextView
android:id="#+id/questionView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.50"
android:autoLink="none"
android:clickable="false"
android:fadingEdge="horizontal"
android:fadingEdgeLength="#dimen/Fading_Edge"
android:includeFontPadding="true"
android:linksClickable="false"
android:longClickable="false"
android:padding="4dp"
android:scrollbars="vertical"
android:text="Question"
android:textSize="25px"
android:typeface="sans" />
Try using solid colors for your textview attributes as follows
android:textColor="#000000"
android:textColorHighlight="#000000"
Use to extend your class with scrollview in java code for scrollablitiy hope the textview color does not change
try this it may help you:
android:focusable="false"
and/or
android:focusableInTouchMode="false"

Moving text in textView android

I would like to ask you if textview has any option that when I have too long text for example text has 30 dp and textview has 15 dp I want to show text which is moving from left corner to right and return to start and again. Something like animation. I want to user see all text. Something like automatic scroll.
Edit: How I can do that in code, not xml?
an example -
in the XML :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="this is a very long piece of text that will move" />
</RelativeLayout>
in Java:
tv = (TextView) this.findViewById(R.id.tv);
tv.setSelected(true); // Set focus to the textview
You should use android:ellipsize="marquee".
EDIT: you can use textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
<TextView
android:id="#+id/YOURID"
android:layout_width="15dp"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
/>
This will help it to scroll until it is focused
Use this code, it's working 100%:
TextView top=new TextView(this);
top.setText("Developers are working to add more features");
top.setEllipsize(TextUtils.TruncateAt.MARQUEE);
top.setHorizontallyScrolling(true);
top.setMarqueeRepeatLimit(-1);
top.setFocusable(true);
top.setFocusableInTouchMode(true);
Yes, its called marquee. Set the following to your TextView:
android:singleLine="true"
android:ellipsize="marquee"
Try this 3 lines codes: (a summary of the above)
textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
textView.setSingleLine(true);
textView.setSelected(true);
In order to move text, besides adding attributes:
android:ellipsize="marquee"
android:singleLine="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
it is necessary for View to be in focus, so this can be done in two ways:
Programmatically:
tv.setSelected (true);
Do everything in XML by adding requestFocus tag:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true">
<requestFocus />
</TextView>

Android: TextView is not scrolling Automatically

I have a TextView with following attributes :
<TextView
android:id="#+id/appheader"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:textColor="#ffffff"
android:layout_marginLeft="3dp"
android:textSize="21sp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"/>
Actually the TextView scrolls ONLY when I click the TextView. But I want to scroll it automatically when I launch the Activity. How can I do this ?
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="very long text to srollll dkfjadkfjkldjfkjdkghjhtudhfjhdjfkdfkadjsajekdfjak"
android:singleLine="true"
android:marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"/>
By-default TextView marquee effect works when it get focus. To make an automatic marquee effect you need to extend TextView class. See this link for reference.
set android:scrollHorizontally="true" for that textview.
Also set the following two properties:
text.setMovementMethod(new ScrollingMovementMethod());
text.setSelected(true);

Categories

Resources