滚动视图中列表视图的滚动功能

San*_*ndy 5 android listview scrollview

在滚动视图中的我的应用程序中,我使用列表视图.但列表视图不滚动.任何人都可以建议我该怎么做.我搜索了它,发现列表视图不在滚动视图中滚动.
有解决方案吗

Cod*_*ter 8

您可以创建自己的列表视图并将expand设置为false.这是示例类

public class ExpandableHeightListView extends ListView {

boolean expanded = false;

public ExpandableHeightListView(Context context) {
    super(context);
}

public ExpandableHeightListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public ExpandableHeightListView(Context context, AttributeSet attrs,
        int defStyle) {
    super(context, attrs, defStyle);
}

public boolean isExpanded() {
    return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // HACK! TAKE THAT ANDROID!
    if (isExpanded()) {
        int expandSpec = MeasureSpec.makeMeasureSpec(
                Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    } else {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

public void setExpanded(boolean expanded) {
    this.expanded = expanded;
}
 }
Run Code Online (Sandbox Code Playgroud)

你可以像这样使用你的activity.clas

 ExpandableHeightListView listview = (ExpandableHeightListView) findViewById(R.id.list);
    listview.setExpanded(true);
Run Code Online (Sandbox Code Playgroud)

在布局文件中,您可以在滚动视图中的列表视图位置使用ExpandableHeightListView.它会滚动.

  • 如果不允许回收物品,使用ListView有什么意义?那么最好使用垂直LinearLayout. (3认同)

Arf*_*rza 5

从ScrollView中排除ListView,因为ListView中已经有滚动机制.

  • 它就像一个表单,所以我不能从滚动视图中排除listView. (2认同)