Kir*_*tin 2 height android textview nestedscrollview
我有一个 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>
Run Code Online (Sandbox Code Playgroud)
TextView 的文本可能很长,但它的长度真的无关紧要,因为在任何情况下,如果它足够大可以滚动——文本的最后一行根本不可见。
这可能是什么原因?
我阅读并尝试了 stackoverflow 上的所有内容,其中包括以下帖子:
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>
Run Code Online (Sandbox Code Playgroud)
Spent an hour on this so i thought it could help someone in the future.
Have a nice day!
| 归档时间: |
|
| 查看次数: |
1466 次 |
| 最近记录: |