사이드 스케이팅 삭제 or 길게 누르면 삭제 안드로이드 신인 스스로 이해하는 삭제
11698 단어 androidListView삭제측면 슬라이드업 삭제긴 누르기 삭제
십중팔구는 틀림없을 것 같다.대체적인 조작도 더 이상 말하지 않겠다.그래서 자신의 방법을 제시한다. 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년 신인이다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.