Android-包含ExpandableListView的NestedScrollView在展开时不会滚动 [英] Android - NestedScrollView which contains ExpandableListView doesn't scroll when expanded

查看:503
本文介绍了Android-包含ExpandableListView的NestedScrollView在展开时不会滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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通过覆盖以下方法来实现任何LisviewGridViewExpandableListView的非滚动属性.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆