NestedScrollView里面的TextView被一条底线截断

TextView inside NestedScrollView is cut off by one bottom line

我有一个 ViewPager 项目,它看起来像这样:

<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>

TextView 的文本可以很长,但它的长度真的无关紧要,因为在任何情况下,如果它足够大以供滚动 - 文本的最后一行根本不可见。

这可能是什么原因?

我阅读并尝试了 Whosebug 上的所有内容,包括这些帖子:

Android: Last line of textview cut off[1]

[2]

TextView in List is cut off[3]

None 的解决方案有效,除了 Rubin Yoo 的解决方案不准确,但与 [1] 中的问题类似。虽然我当时没有看到它,并且可能不会尝试,因为情况完全不同,所以我继续搜索并找到了这个 link:

https://www.reddit.com/r/androiddev/comments/4c6ri4/long_text_in_a_nestedscrollview/

那是一个完美的打击。因此,根据规则的要求,这里是其中的答案片段:

Put the textview inside a FrameLayout - @samyboy89

以及我同意的可能解释:

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

所以工作布局是:

<?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>

在这上面花了一个小时所以我认为它可以帮助将来的人。

祝你有愉快的一天!