San*_*ndy 5 android listview scrollview
在滚动视图中的我的应用程序中,我使用列表视图.但列表视图不滚动.任何人都可以建议我该怎么做.我搜索了它,发现列表视图不在滚动视图中滚动.
有解决方案吗
您可以创建自己的列表视图并将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.它会滚动.
| 归档时间: |
|
| 查看次数: |
2707 次 |
| 最近记录: |