Android 更改onScroll()中的ListView项高度会导致警告
我有一个Listview,我正在onScroll回调中动态更改Android 更改onScroll()中的ListView项高度会导致警告,android,android-listview,Android,Android Listview,我有一个Listview,我正在onScroll回调中动态更改Listview项目高度 问题是我收到了以下警告: 05-29 14:41:16.935: W/View(1629): requestLayout() improperly called by android.widget.RelativeLayout{42701a80 V.E..... ......ID 0,0-768,600 #7f060133 app:id/parent} during layout: running secon
Listview
项目高度
问题是我收到了以下警告:
05-29 14:41:16.935: W/View(1629): requestLayout() improperly called by android.widget.RelativeLayout{42701a80 V.E..... ......ID 0,0-768,600 #7f060133 app:id/parent} during layout: running second layout pass
并且总是调用onScroll
回调,即使用户没有滚动它,下面是我的代码:
listview.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (adapter != null) {
for (int i = 0; i < visibleItemCount; i++) {
//the listview view
View v = adapter.getParentView(firstVisibleItem + i);
if (v != null) {
LayoutParams lp = v.getLayoutParams();
lp.height = //some height manipulation according to the view position
v.setLayoutParams(lp); //this line causes the warning
}
}
}
}
});
listview.setOnScrollListener(新的OnScrollListener(){
@凌驾
公共无效onScrollStateChanged(AbsListView视图,int scrollState){
}
@凌驾
public void onScroll(AbsListView视图、int firstVisibleItem、int visibleItemCount、int totalItemCount){
if(适配器!=null){
对于(int i=0;i
我的目标是每次在屏幕上的项目位置上卸载时,将listview项目高度更改1px
问题:如何在
onScroll
回调中设置视图LayoutParams
解决方案是使用setLayoutParams()
调用在活套上发布runnable
v.post(new Runnable() {
@Override
public void run() {
v.setLayoutParams(lp);
}
});
@Mohammadabuqaud我已经调查了这些问题,我还没有找到解决办法。