【问题标题】:TextView inside NestedScrollView is cut off by one bottom lineNestedScrollView 内的 TextView 被底线截断
【发布时间】:2018-09-08 13:26:21
【问题描述】:

我有一个 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 的文本可以很长,但它的长度实际上并不重要,因为无论如何它是否足够大以进行滚动 - 文本的最后一行根本不可见。

这可能是什么原因?

【问题讨论】:

    标签: android textview height nestedscrollview


    【解决方案1】:

    我阅读并尝试了 stackoverflow 上的所有内容,包括以下帖子:

    Android: Last line of textview cut off[1]

    Android Textview text cut off at bottom[2]

    TextView in List is cut off[3]

    没有任何解决方案有效,除了 Rubin Yoo 对 [1] 中的不精确但类似问题的解决方案。虽然我当时没有看到,可能不会尝试,因为情况不同,所以我继续搜索并找到了这个链接:

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

    这是一个完美的打击。因此,正如规则中所要求的,这是来自它的答案 sn-p:

    将 textview 放入 FrameLayout - @samyboy89

    以及我同意的可能解释:

    我认为滚动视图无法正确计算需要滚动的高度是一个问题。使用框架布局,它只获取框架布局的高度,它正确计算出文本视图的高度。 - @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>
    

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

    祝你有美好的一天!

    【讨论】:

    • 我的配置与您的相同,但无法正常工作。可能是因为我在一个高度可变的元素(使用权重)中有NestedScrollView。幸运的是,我没有嵌套滚动视图,我可以使用 ScrollView 让它工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-03
    相关资源
    最近更新 更多