2013-09-30 68 views
1

混亂的列表視圖項目時,滑落效果會擴大列表視圖項目的可見性問題。我試圖在我的列表視圖中實現this的想法,並面臨以下問題在滾動的同時滾動

在Onitemclick()最後可見視圖關閉,並顯示新視圖,但它的工作,但第一個項目是可見的和滾動後的ListView我看到其他項目也是可見的,無需用戶點擊。 任何建議如何保持滾動時唯一可見的項目。

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); 
} 

回答

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

+0

如何使用這個邏輯在哪裏? – user755

+0

看到這一個http://theopentutorials.com/tutorials/android/listview/android-expandable-list-view-example/ – NagarjunaReddy

+0

我不想expandablelistview。請檢出我的問題中發佈的鏈接。 – user755