Reputation: 928
I have a ViewPager items of which look like this:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingLeft="@dimen/material_horizontal_margin"
android:paddingRight="@dimen/material_horizontal_margin"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/group_footer_pager_item_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left"/>
</android.support.v4.widget.NestedScrollView>
The text of TextView's can be really long, but the length of it really does not matter as in any case if it is big enough for scrolling - the last line of the text would be NOT visible at all.
What can be the cause of that?
Upvotes: 2
Views: 2380
Reputation: 928
I read and tried everything on stackoverflow which includes these posts:
Android: Last line of textview cut off [1]
Android Textview text cut off at bottom [2]
TextView in List is cut off [3]
None of the solutions had worked, except the Rubin Yoo's solution for not exact, but similar problem from [1]. Though i had not seen it at the time, and probably would not try it as the case was quite different, so i continued searching and found this link:
https://www.reddit.com/r/androiddev/comments/4c6ri4/long_text_in_a_nestedscrollview/
That was a perfect hit. So, as it is required in the rules, here is the answer snippet from it:
Put the textview inside a FrameLayout - @samyboy89
And the probable explanation with which i agree:
I think it's an issue with the scroll view being unable to correctly calculate the height that needs to scroll. With the frame layout, it just gets the height of the frame layout, which correctly figured out the height of the text view. - @Nintynien
So the working layout is:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingLeft="@dimen/material_horizontal_margin"
android:paddingRight="@dimen/material_horizontal_margin"
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- FrameLayout is needed for the correct TextView's height
calculation. As without it the last line would be cut off.-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/group_footer_pager_item_info"
style="@style/RobotoRegular.Black.Big"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left"/>
</FrameLayout>
</android.support.v4.widget.NestedScrollView>
Spent an hour on this so i thought it could help someone in the future.
Have a nice day!
Upvotes: 6