I'm having a bit of an issue with a text view embedded within a scroll view. When the text becomes 4 lines or so, I'm unable to scroll to the top line of the text - although I can scroll to one line past the last line of the text.
Here's the layout:
<ScrollView android:layout_width="wrap_content"
android:layout_height="90sp"
android:scrollbars="vertical">
<TextView android:id="@+id/display开发者_开发问答_english"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="10dp" android:layout_gravity="center_vertical|center_horizontal"
android:textSize="30sp" android:textColor="@color/text_color" />
</ScrollView>
Any thoughts?
If you're just trying to make your TextView scrollable, then you do not need to embed it in a ScrollView
. I would check out this solution.
After extensively reviewing this problem in code and online, currently the only viable solutions to get a TextView to scroll vertically inside a ScrollView appear to be:
1) If a vertically-oriented layout isn't absolutely necessary, change the containing ScrollView to a HorizontalScrollView and arrange its children (including the scrollable TextView) in a horizontal orientation. This way, the horizontal scrolling of the HorizontalScrollView will not interfere with the vertical scrolling of the TextView.
2) If a vertically-oriented layout IS absolutely necessary, don't try to get the TextView to scroll vertically inside a vertical ScrollView, at all. Instead, set the height of the TextView to "WRAP_CONTENT", since this will ensure the content of the TextView will be visible in its entirety without scrolling. This works, because you are not concerned with the absolute height of the child-layout, since you want to use a vertical ScrollView in the first place.
精彩评论