在滚动时向下滑动扩展列表视图项目可见性问题的效果

时间:2013-09-30 08:19:28

标签: android listview android-listview

滚动时混乱的listview项目。我正在尝试在列表视图中实现this想法,并面临以下问题

在Onitemclick()下关闭最后一个可见视图并显示新视图,其工作正常但当第一个项目可见时,滚动列表视图后,我看到其他项目在没有用户点击的情况下也可见。 任何建议如何在滚动时保持只有一个项目可见。

Actitvity:

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
View last_dropdownBarview=null;

 ViewHolder holder = (ViewHolder) arg1.getTag();
    final View dropDown = holder.dropdownBarview;

if(last_dropdownBarview!=null)
{
    last_dropdownBarview.setVisibility(View.GONE);
}

ExpandCollapseAnimation.setHeightForWrapContent(MainActivity.this, dropDown);
ExpandCollapseAnimation expandAni = new ExpandCollapseAnimation(dropDown, DROP_DOWN_TIME);
dropDown.startAnimation(expandAni);

last_dropdownBarview= dropDown;

}

适配器类:

static class ViewHolder {
    .
    .
    protected View dropdownBarview;

}

public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder viewHolder = null;
    if (convertView == null) {

        LayoutInflater inflator = context.getLayoutInflater();
        convertView = inflator.inflate(R.layout.row, null);
        viewHolder = new ViewHolder();

        viewHolder.dropdownBarview= convertView.findViewById(R.id.toolbar);
        convertView.setTag(viewHolder);
        convertView.setTag(R.id.dropdownbar,viewHolder.dropdownBarview);            
    }
    else {
        viewHolder = (ViewHolder) convertView.getTag();
    }

    viewHolder.dropdownBarview.setTag(position);
}

1 个答案:

答案 0 :(得分:0)

一旦看到这里

   DisplayMetrics metrics = new DisplayMetrics();
   getWindowManager().getDefaultDisplay().getMetrics(metrics);
   int width = metrics.widthPixels; 

 mExpandableList = (ExpandableListView)findViewById(R.id.expandable_list);
 mExpandableList.setIndicatorBounds(width - GetPixelFromDips(50), width - GetPixelFromDips(10));  

    public int GetPixelFromDips(float pixels) {
     // Get the screen's density scale 
      final float scale = getResources().getDisplayMetrics().density;
     // Convert the dps to pixels, based on density scale
   return (int) (pixels * scale + 0.5f);
 }

see this one working fine