Why my TextView is Scrolling?
<TextView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_logo_header"
android:layout_marginTop="5dp"
android:autoLink="web"
android:descendantFocusability="blocksDescendants"
android:ellipsize="end"
android:focusable="false"
android:maxLines="3"
android:text="Should my school be focused on -- Teaching and Learning come as words which are very closely related, But they convey very different meanings and can not be used interchangeably."
android:textColor="#color/black" />
The content for this view could be text and may also contain HTML content. Hence I have set autoLink to true. The issue is, if either the autoLink or the textIsSelectable is true, then the textview starts to scroll similar to(MovementMethod) when its content is more than 3 lines. I am looking for a way to stop/disable this textview scrolling.
I tried to disable the scrolling using setEnable(false) for the text view, however all the links in the textview could not be clicked thereafter.
I think there has to be a straight forward way to achieve "non-scrollable textview" which may contain html content in them.
autoLink controls whether the TextView will parse URLs and highlight them as such. It has nothing to do with rendering HTML.
Your TextView is scrolling because you've set android:maxLines="3"
Related
A screen in my app will potentially post really long strings into a TextView. For this scenario, I have android:ellipsize="marquee" set so the text will marquee across the TextView.
However, I've decided I also want this text to be selectable (android:textIsSelectable="true"). In most cases, this is no problem. The text is smaller than the TextView and the user can just select it. However, if I have the textIsSelectable attribute and if the text is bigger than the TextView, the text will pick up an ellipse instead of being the full string. It will still marquee, but it no longer displays the full text. It cuts it off and displays an ellipse.
<TextView
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:ellipsize="marquee"
android:focusable="true"
android:gravity="center_vertical"
android:singleLine="true"
android:textIsSelectable="true">
Is there a way to have the text selectable and still maintain the entire string in the marquee (no ellipse)?
Can't be sure if this is a bug.
<TextView
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:ellipsize="start"
android:focusable="true"
android:gravity="center_vertical"
android:singleLine="true"
android:textIsSelectable="true"/>
Note that we're setting android:ellipsize="start" in xml - more on this later.
mTextView = (TextView) findViewById(R.id.tv);
mTextView.post(new Runnable() {
#Override
public void run() {
mTextView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
mTextView.setSelected(true);
}
});
setEllipsize(TruncateAt) checks whether the current ellipsize value is the same as the supplied one. To get around this, we supply android:ellipsize="start" in xml. This way, the TextView has no problem accepting TextUtils.TruncateAt.MARQUEE later on.
Now, even though this works, I will suggest you don't do this. You'll be able to see why - once you try this code. It seems textIsSelectable is not supposed to be used with marquee - the selection handles don't move along with the text.
All in all, it looks extremely sketchy.
I have a textview configured in my XML as below.
<RelativeLayout>
<!-- more views here like ImageView and other TextView-->
<TextView
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="4"
android:textIsSelectable="false"
android:autoLink="web|phone|email"/>
</RelativeLayout>
The content for this view could be text and may also contain HTML content. Hence I have set autoLink to true. The issue is, if either the autoLink or the textIsSelectable is true, then the textview starts to scroll similar to(MovementMethod) when its content is more than 4 lines. I am looking for a way to stop/disable this textview scrolling.
I tried to disable the scrolling using setEnable(false) for the text view, however, all the links in the textview could not be clicked thereafter.
I think there has to be a straight forward way to achieve "non-scrollable textview" which may contain HTML content in them.
I think you can add the attribute android:nestedScrollingEnabled="false" to any View child. At least, I use android:nestedScrollingEnabled="true" to make my TextViews scrollable. Hope this solves your problem.
BTW, why are you trying to display a clickable link when you can't even scroll to look at the entire link? Just asking out of curiosity.
set ellipsize to the text view so text can't be greater than 4 lines
may be this is solution for you
Try changing 'Relative Layout' to 'Table layout'... If this doesn't work then try to set appropriate padding and margin for Textview and other widgets.
I have a listview where each item has 2 images, one on the right and the other on the left. Between them there is a textview that is filled from data. If text is long then it can continue down but there is a lot of free space just as you can see in the image. I want to use this space also to display text. I have been looking around the web and I have seen things like this http://code.google.com/p/android-flowtextview/downloads/detail?name=FlowTextDemo.zip&can=2&q= but this is useless. I don't want to lose the control of the images because I need their click method. What is the best way to do it? I have thought that maybe I can put a textview between images and an other down and when the first is filled continue in the second one but how can I know how many letters can keep the first textview?
I don't understand why FlowTextView (that you linked to) won't work for you. It's derived from RelativeLayout and flows text around any child views. The child views can be your images, positioned as you normally would in a RelativeLayout. Their onClick methods should work just fine.
<com.pagesuite.flowtext.FlowTextView
android:id="#+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/the_text >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:onClick="onTopLeftClick"
android:src="#drawable/top_left_image" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:onClick="onTopRightClick"
android:src="#drawable/top_right_image" />
</com.pagesuite.flowtext.FlowTextView>
You will need to set the text in code, or else extend FlowTextView and define your own custom attribute(s) to do it from xml.
I want to display multiple lines of text in my application in particular range such that user can scroll to view other lines. I have tried EditText, but it generates keyboard on top of it and doesn't scroll properly. Then I tried TextView, it also does not scroll the text properly as I wanted.
Is there any other option available? If No, then how to scroll the text vertically in TextView or EditText? I want to scroll the text on drag as in WebView. NOT auto scroll.
You can limit the Height of TextView to match the number of lines you user wants to see, then simply put your TextView in a ScrollView
I had done a simple example to demonstrate this...
<ScrollView android:layout_height="30dp"
android:layout_width="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:textSize="16sp"
android:id="#+id/tv1"
/>
</ScrollView>
Check below code
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="17dip"
android:inputType="textMultiLine"
android:scrollbars="vertical"
/>
It is possible to create multiline text view with scroll view. I used the following code in your application:
Txt_VistaRecetasola = (TextView) findViewById(R.id.txt_vistarectsola);
Txt_VistaRecetasola.setMovementMethod(ScrollingMovementMethod.getInstance());
Txt_VistaRecetasola.setScrollBarStyle(0x03000000);
Txt_VistaRecetasola.setVerticalScrollBarEnabled(true);
Txt_VistaRecetasola.setTextColor(0xFF000000);
Try using Edittext with making it un editable, so in this case it wont allow keyboard to popup.
android:windowSoftInputMode="stateAlwaysHidden" in your Manifest file in the activity where you have your EditText.
I have a expandable list view consisting of varied sized textviews. The TextView size depends upon the contents in it. Now there are certain text which exceeds the screen width and the user is not able to view it.
I have tried HorizontolScrollView inside a ScrollView. It performs the scrolling but as my UI is a bit complex, it doesnot renders the other widgets in the view (like checkbox) properly.
Please suggest some good ideas to do the manual text scrolling.
Marquee is not a good suggestion. :)
Thanks in advance
Nested scroll view is a big 'no no' in android as there is no good way to determine which scroll has focus.
My solution would be to make an non-editable EditText. I would do something like this.
<EditText android:scrollHorizontally="true"
android:editable="false"
android:enabled="false"
android:layout_width="match_parent"
android:id="#+id/editText1"
android:layout_height="wrap_content" >
</EditText>
TextView seems to have a android:scrollHorizontally property as well but I have had no luck getting it to function.