如何在Android中设置NestedScrollView的最大高度?

问题描述 投票:3回答:1

我在NestedScrollView内有一个ScrollViewNestedScrollView包含TextView。因此,当TextView扩展到4或n线以上时,我需要使它成为Scrollable TextView

任何帮助深表感谢!!

textview android-nestedscrollview android
1个回答
1
投票

我希望你现在必须解决这个问题。如果将来有人查找,您无需设置最大高度。只需将NestedScrollView的高度设置为37f,只要文本大小超过37,NestedScrollView就会开始滚动。

XML:

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
        android:layout_height="wrap_content">
...
</android.support.v4.widget.NestedScrollView>

或以编程方式:

NestedScrollView nsv = new NestedScrollView(getActivity());
// Initialize Layout Parameters
RelativeLayout.LayoutParams nsvParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 38));
// Set Layout Parameters 
nsv.setLayoutParams(nsvParams);
© www.soinside.com 2019 - 2024. All rights reserved.