Android-包含ExpandableListView的NestedScrollView在展开时不会滚动 [英] Android - NestedScrollView which contains ExpandableListView doesn't scroll when expanded
问题描述
我在NestedScrollView
中有一个ExpandableListView
(是的,我知道,在另一个滚动视图中有一个滚动视图不是很好,但是我不知道该怎么做,如果有人知道,请告诉我更好的方法).
I have an ExpandableListView
inside a NestedScrollView
(yes I know, it is not good to have a scrolling view inside another scrolling view but I don't know what else to do, please do tell me if anybody knows a better approach).
NestedScrollView
中内容的大小仍在屏幕内,因此不会滚动,但是ExpandableListView
展开时,内容将泄漏到屏幕外,但NestedScrollView
仍不会滚动.为什么会这样?
The size of the content in NestedScrollView
is still within the screen so it won't scroll, but when ExpandableListView
is expanded, the content will leak outside the screen but the NestedScrollView
still won't scroll.. Why is this so?
这是我的NestedScrollView
布局:
<NestedScrollView>
<LinearLayout>
<LinearLayout></LinearLayout>
... // About 3 of the LinearLayouts
<ExpandableListView/>
</LinearLayout>
</NestedScrollView>
推荐答案
您可以使用NonScrollExpandableListView
通过覆盖以下方法来实现任何Lisview
或GridView
或ExpandableListView
的非滚动属性.>
You can use NonScrollExpandableListView
you can achieve non-scroll property of any Lisview
or GridView
or ExpandableListView
by overriding following method.
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
因此,要使用NonScrollExpandableListView
,您需要创建一个自定义类.
So for using NonScrollExpandableListView
you need to make one custom class.
public class NonScrollExpandableListView extends ExpandableListView {
public NonScrollExpandableListView(Context context) {
super(context);
}
public NonScrollExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NonScrollExpandableListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
}
并像这样使用它.
<com.example.extraclasses.NonScrollExpandableListView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
快乐的编码.
这篇关于Android-包含ExpandableListView的NestedScrollView在展开时不会滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!