android 仿qq删除,Android仿QQ微信侧滑删除效果

3.所用到的布局文件

—swipecontent.xml代码

android:id="@+id/rl_layout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#999999"

android:padding="8dp" >

android:id="@+id/iv_icon"

android:layout_width="50dp"

android:layout_height="50dp"

android:src="@drawable/ic_launcher" />

android:id="@+id/tv_name"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:layout_marginLeft="10dp"

android:layout_toRightOf="@+id/iv_icon"

android:text="name"

android:textColor="@android:color/black"

android:textSize="18sp" />

—swipemenu.xml代码

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:orientation="horizontal"

>

android:id="@+id/tv_open"

android:layout_width="90dp"

android:layout_height="match_parent"

android:gravity="center"

android:background="#C2C2C2"

android:text="置顶"

android:textColor="@android:color/white"

android:textSize="18sp" />

android:id="@+id/tv_del"

android:layout_width="90dp"

android:layout_height="match_parent"

android:gravity="center"

android:background="#FF0000"

android:text="删除"

android:textColor="@android:color/white"

android:textSize="18sp" />

4.主界面代码

public class MainActivity extends Activity {

private List mAppList;

private DragDelListView mListView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_list);

mAppList = getPackageManager().getInstalledApplications(0);

mListView = (DragDelListView) findViewById(R.id.listView);

mListView.setAdapter(new AppAdapter(mAppList));

}

class AppAdapter extends BaseAdapter {

private List mAppList;

public AppAdapter(List appList)

{

mAppList=appList;

}

@Override

public int getCount() {

return mAppList.size();

}

@Override

public ApplicationInfo getItem(int position) {

return mAppList.get(position);

}

@Override

public long getItemId(int position) {

return position;

}

@Override

public View getView(final int position, View convertView, ViewGroup parent) {

ViewHolder holder=null;

View menuView=null;

if (convertView == null) {

convertView = View.inflate(getApplicationContext(),

R.layout.swipecontent, null);

menuView = View.inflate(getApplicationContext(),

R.layout.swipemenu, null);

convertView = new DragDelItem(convertView,menuView);

holder=new ViewHolder(convertView);

} else {

holder = (ViewHolder) convertView.getTag();

}

ApplicationInfo item = getItem(position);

holder.iv_icon.setImageDrawable(item.loadIcon(getPackageManager()));

holder.tv_name.setText(item.loadLabel(getPackageManager()));

holder.tv_open.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View arg0) {

Toast.makeText(MainActivity.this, "置顶:"+position, Toast.LENGTH_SHORT).show();

}

});

holder.tv_del.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View arg0) {

Toast.makeText(MainActivity.this, "删除:"+position, Toast.LENGTH_SHORT).show();

}

});

return convertView;

}

class ViewHolder {

ImageView iv_icon;

TextView tv_name;

TextView tv_open,tv_del;

RelativeLayout relativeLayout;

public ViewHolder(View view) {

iv_icon = (ImageView) view.findViewById(R.id.iv_icon);

tv_name = (TextView) view.findViewById(R.id.tv_name);

tv_open=(TextView)view.findViewById(R.id.tv_open);

tv_del=(TextView)view.findViewById(R.id.tv_del);

relativeLayout = (RelativeLayout) view.findViewById(R.id.rl_layout);

//改变relativeLayout宽度

WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);

int width = wm.getDefaultDisplay().getWidth();

relativeLayout.setMinimumWidth(width-60);

view.setTag(this);

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值