【问题标题】:how to make an ImageView visible on swiping a listview row?如何在滑动列表视图行时使 ImageView 可见?
【发布时间】:2014-05-31 02:57:34
【问题描述】:

我使用<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>

我想让 ImageView ii 在 listview 行向左滑动时可见,并在 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"
        />

【问题讨论】:

    标签: android listview imageview visibility swipe


    【解决方案1】:

    你可以像这样检查 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);
                }                   
            }
        });
    

    【讨论】:

    • ImageView 在 if(x
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-23
    • 2012-01-13
    • 1970-01-01
    相关资源
    最近更新 更多