如何在刷列列表视图行时使ImageView可见?

时间:2014-04-16 09:56:32

标签: android listview imageview visibility swipe

我使用<com.fortysevendeg.swipelistview.SwipeListView>生成了ListView。我使用以下xml来获取SimpleAdapter

中的项目
custom_row.xml

  <LinearLayout
        android:id="@+id/back"
        style="@style/MyListBackContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:tag="back" 
       >

        <ImageView
            android:id="@+id/example_imagess"
            android:layout_width="50dp"
            android:layout_height="60dp"
            android:background="#8250a5"
            android:visibility="gone"
            android:src="@drawable/ic_status" />




    </LinearLayout>
     <RelativeLayout
     android:id="@+id/front"

     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"


     android:tag="front" >

     <ImageView
         android:id="@+id/imageView1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignBottom="@+id/example_itemname"
         android:layout_alignParentRight="true"
         android:src="@drawable/ic_action_search" />
        </RelativeLayout>

当listview行向左滑动时,我想让ImageView ii可见,当listview行向右滑动时,我想隐藏相同的imageview ii。 myfriends扩展了Fragment类

  ListAdapter k=new SimpleAdapter(getActivity(),val,R.layout.custom_row,new String[]{"fbname"},new int[]{R.id.example_itemname}){

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
             final View v = super.getView(position, convertView, parent);
             final ImageView ii=(ImageView)v.findViewById(R.id.example_imagess);
            // final View orange=(View)v.findViewById(R.id.orangeview);
             swipy.setSwipeListViewListener(new BaseSwipeListViewListener(){

                @Override
                public void onOpened(int position, boolean toRight) {
                    // TODO Auto-generated method stub
                    super.onOpened(position, toRight);
                    //swipy.setBackgroundColor(Color.BLACK);
                }

                @Override
                public void onClickFrontView(int position) {
                    // TODO Auto-generated method stub
                    super.onClickFrontView(position);

                    swipy.setBackgroundDrawable(getResources().getDrawable(R.drawable.swipy_list_color));

                }

                @Override
                public int onChangeSwipeMode(int position) {
                    // TODO Auto-generated method stub
                    Toast.makeText(getActivity(),"onchangeSwipeMode",Toast.LENGTH_SHORT).show();

                    swipy.setBackgroundDrawable(getResources().getDrawable(R.drawable.swipy_list_color));
                    ii.setVisibility(v.VISIBLE);

                    return super.onChangeSwipeMode(position);
                }

我的swipelistview如下:

       <com.fortysevendeg.swipelistview.SwipeListView
        android:id="@+id/example_swipe_lv_list"

        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        swipe:swipeFrontView="@+id/front"
        swipe:swipeBackView="@+id/back"

        android:listSelector="@drawable/list_selector"
  android:choiceMode="singleChoice"
        swipe:swipeDrawableChecked="@drawable/choice_selected"
        swipe:swipeDrawableUnchecked="@drawable/choice_unselected"
        swipe:swipeCloseAllItemsWhenMoveList="true"

        swipe:swipeMode="both"
        />

1 个答案:

答案 0 :(得分:0)

您可以像这样检查x。

您不应在适配器中设置swipeListViewListener,请尝试在您的活动或片段中设置它。您现在在适配器getView()中执行此操作的方法是为列表中的每一行设置一个新的swipeListViewListener到listView。

// In your activity/fragment
swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() {
        @Override
        public void onMove(int position, float x) {
            super.onMove(position, x);
            int index = position - swipeListView.getFirstVisiblePosition();
            View currentRow = swipeListView.getChildAt(index);
            ImageView imageView = (ImageView) currentRow.findViewById(IMAGE_ID);

            if (x < 0) {
                // RIGHT, hide your imageView
                imageView.setVisibility(View.INVISIBLE);
            }
            else {
                // LEFT, show your imageView
                imageView.setVisibility(View.VISIBLE);
            }                   
        }
    });