사이드 스케이팅 삭제 or 길게 누르면 삭제 안드로이드 신인 스스로 이해하는 삭제

사이드 스케이팅 삭제는 모든 신인들이 안드로이드를 접할 때 매우 흥분하는 컨트롤러이다. 나도 마찬가지다. 나는 안드로이드의 1년 신인이고 자신의 이해에 따라 이런 사이드 스케이팅 삭제를 실현한다.거칠지만 튼튼해요.먼저 위의 그림.
십중팔구는 틀림없을 것 같다.대체적인 조작도 더 이상 말하지 않겠다.그래서 자신의 방법을 제시한다. 1.listvie에서 여러 개의 레이아웃을 불러옵니다. 2.모든 item 안에는 horizon Scrollview 안에 두 개의relative Layout을 끼워 넣으면 이렇게 간단하고 코드에 바로 올라갑니다.
MainAcitity acitivty

public class MainActivity extends Activity {

    private ListView  listview;
    private List<Map<String, String>>list = new ArrayList<Map<String,String>>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        setviews();

        setAdapter();

    }


    private void setviews() {
        listview = (ListView) findViewById(R.id.listview);

    }

    private void setAdapter() {
        list = new ArrayList<Map<String,String>>();
        for (int i = 0; i < 20; i++) {
            Map<String, String>map = new HashMap<String, String>();
            map.put("1", "   "+i+"   ");
            list.add(map);
        }

        MyAdapter adapter = new MyAdapter(this, list);
        listview.setAdapter(adapter);

    }

}


MyAdapter    

public class MyAdapter extends BaseAdapter{

    private Context context;
    private List<Map<String, String>>list = new ArrayList<Map<String,String>>();

    public MyAdapter(Context context , List<Map<String, String>>list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        holder = new ViewHolder();
        convertView = View.inflate(context, R.layout.item, null);
        holder.tv = (TextView) convertView.findViewById(R.id.tv);
        holder.holrzon_sc = (HorizontalScrollView) convertView.findViewById(R.id.holrzon_sc);
        holder.rl01 = (RelativeLayout) convertView.findViewById(R.id.rl01);
        holder.rl02 = (RelativeLayout) convertView.findViewById(R.id.rl02);
        convertView.setTag(holder);

        holder.tv.setText(list.get(position).get("1"));
        holder.rl01.setOnLongClickListener(new  OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                holder.holrzon_sc.smoothScrollTo(200,0);//HorizonScrollview   100dp   
                return true;//   setOnClickListener  
            }
        });
        holder.rl01.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                holder.holrzon_sc.smoothScrollTo(0,0);//HorizonScrollview   0dp   
            }
        });

        holder.rl02.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                list.remove(position);//    position
                notifyDataSetChanged();//    
            }
        });
        holder.holrzon_sc.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });

        return convertView;
    }

    class ViewHolder{
        TextView tv;
        HorizontalScrollView holrzon_sc;
        RelativeLayout rl01;
        RelativeLayout rl02;
    }

}

//xml  
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <HorizontalScrollView
        android:id="@+id/holrzon_sc"
        android:layout_width="wrap_content"
        android:background="@null"
        android:scrollbars="@null"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="80dp"
            android:orientation="horizontal" >

            <RelativeLayout
                android:id="@+id/rl01"
                android:layout_width="360dp"
                android:layout_height="80dp"
                android:background="#ffffff" >

                <TextView
                    android:id="@+id/tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="20dp"
                    android:text="   "
                    android:textColor="#1a1a1a"
                    android:textSize="16sp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="0.5dp"
                    android:layout_alignParentBottom="true"
                    android:background="#dcdcdc" />
            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/rl02"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="#f02030" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:text="  "
                    android:textColor="#ffffff"
                    android:textSize="16sp" />
            </RelativeLayout>
        </LinearLayout>
    </HorizontalScrollView>

</RelativeLayout>

//mainactivity xml  

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView 
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@null"
        android:divider="@null"
        android:scrollbars="@null"
        android:listSelector="@android:color/transparent"
        ></ListView>

</RelativeLayout>

내용도 간단하고 이해도 잘 되고 초라하고 능력도 한계가 있다고 할 수 밖에 없어요. 계속 보완하고 힘내세요.나는 안드로이드 1년 신인이다.

좋은 웹페이지 즐겨찾기