本文介绍了新的Android应用程序的收件箱列表视图风格与刷卡左,右的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
米力图打造的android新的收件箱风格的ListView有刷卡左,右,如图这一形象,我已经尝试过 47deg swipelistview 一>,但它不是稳定,是否有任何其他库可用?!
试过到目前为止有47度
公共类MainActivity延伸活动{
列表视图pullToRefreshListView;
SwipeListView swipelistview;
ItemAdapter适配器;
名单< ItemRow>的ItemData;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
pullToRefreshListView =(ListView控件)findViewById(R.id.example_swipe_lv_list);
swipelistview = pullToRefreshListView.getRefreshableView();
的ItemData =新的ArrayList< ItemRow>();
适配器=新ItemAdapter(这一点,R.layout.custom_row,的ItemData);
swipelistview.setSwipeListViewListener(新BaseSwipeListViewListener(){
@覆盖
公共无效onOpened(INT位置,布尔toRight){
如果(toRight){
adapter.remove(位置);
Toast.makeText(MainActivity.this,开放解雇,
Toast.LENGTH_SHORT).show();
} // swipelistview.dismiss(位置);
其他 {
Toast.makeText(MainActivity.this,打开编辑,
Toast.LENGTH_SHORT).show();
}
}
@覆盖
公共无效onClosed(INT位置,布尔fromRight){
}
@覆盖
公共无效onListChanged(){
}
@覆盖
公共无效onMove(INT位置,浮X){
}
@覆盖
公共无效onStartOpen(INT位置,INT动作,布尔右){
如果(右){
// adapter.onRight();
swipelistview.getChildAt(位置).findViewById(R.id.back)
.setBackgroundColor(Color.GREEN);
swipelistview.getChildAt(位置)
.findViewById(R.id.imageViewLeft)
.setVisibility(View.VISIBLE);
swipelistview.getChildAt(位置)
.findViewById(R.id.imageViewRight)
.setVisibility(View.GONE);
} 其他 {
// adapter.onLeft();
swipelistview.getChildAt(位置).findViewById(R.id.back)
.setBackgroundColor(Color.RED);
swipelistview.getChildAt(位置)
.findViewById(R.id.imageViewLeft)
.setVisibility(View.GONE);
swipelistview.getChildAt(位置)
.findViewById(R.id.imageViewRight)
.setVisibility(View.VISIBLE);
}
}
@覆盖
公共无效onStartClose(INT位置,布尔右){
Log.d(刷卡,的String.Format(onStartClose%D位置));
}
@覆盖
公共无效onClickFrontView(INT位置){
Log.d(刷卡,的String.Format(onClickFrontView%D位置));
// swipelistview.openAnimate(位置);当你触摸前面//
//查看它就会打开
}
@覆盖
公共无效onClickBackView(INT位置){
Log.d(刷卡,的String.Format(onClickBackView%D位置));
// swipelistview.closeAnimate(位置); //当你触摸回
//查看它会关闭
}
@覆盖
公共无效onDismiss(INT [] reverseSortedPositions){
}
});
//这些都是刷卡列表视图设置。你可以改变这些
//设置根据您的要求
swipelistview.setSwipeMode(SwipeListView.SWIPE_MODE_BOTH); // 有
// 五
//刷卡
//模式
swipelistview.setSwipeActionRight(SwipeListView.SWIPE_ACTION_REVEAL); // 那里
//是
// 四
//刷卡
//行动
swipelistview.setSwipeActionLeft(SwipeListView.SWIPE_ACTION_REVEAL);
swipelistview.setOffsetRight(convertDpToPixel(0F)); // 左边
// 抵消
swipelistview.setOffsetLeft(convertDpToPixel(0F)); // 右边
// 抵消
swipelistview.setAnimationTime(60); //动画时间
swipelistview.setSwipeOpenOnLong preSS(假); //启用或禁用
// SwipeOpenOnLong preSS
swipelistview.setSwipeCloseAllItemsWhenMoveList(真正的);
swipelistview.setAdapter(适配器);
的for(int i = 0;我小于10;我++){
itemData.add(新ItemRow(刷卡项目+ I,getResources()
.getDrawable(R.drawable.ic_launcher)));
}
adapter.notifyDataSetChanged();
}
公众诠释convertDpToPixel(浮点DP){
DisplayMetrics指标= getResources()getDisplayMetrics()。
浮动PX = DP *(metrics.densityDpi / 160F);
返回(INT)像素;
}
}
适配器类
公共类ItemAdapter扩展ArrayAdapter< ItemRow> {
名单< ItemRow>数据;
上下文语境;
INT layoutResID;
公共ItemAdapter(上下文的背景下,INT layoutResourceId,名单,其中,ItemRow>数据){
超级(上下文,layoutResourceId,数据);
this.data =数据;
this.context =背景;
this.layoutResID = layoutResourceId;
// TODO自动生成构造函数存根
}
NewsHolder支架=无效;
查看排= NULL;
@覆盖
公共查看getView(INT位置,查看convertView,ViewGroup中父){
行= convertView;
支架=无效;
如果(行== NULL){
LayoutInflater充气=((活动)上下文).getLayoutInflater();
行= inflater.inflate(layoutResID,父母,假);
持有人=新NewsHolder();
holder.itemName =(TextView中)一行
.findViewById(R.id.example_itemname);
holder.icon =(ImageView的)row.findViewById(R.id.example_image);
holder.imageViewRight =(ImageView的)行
.findViewById(R.id.imageViewRight);
holder.imageViewLeft =(ImageView的)行
.findViewById(R.id.imageViewLeft);
row.setTag(保持器);
} 其他 {
支架=(NewsHolder)row.getTag();
}
ItemRow的ItemData = data.get(位置);
holder.itemName.setText(itemdata.getItemName());
holder.icon.setImageDrawable(itemdata.getIcon());
返回行;
}
公共无效删除(INT POS){
data.remove(POS);
}
公共无效onLeft(){
holder.imageViewLeft.setVisibility(View.VISIBLE);
holder.imageViewRight.setVisibility(View.GONE);
}
公共无效onRight(){
holder.imageViewRight.setVisibility(View.VISIBLE);
holder.imageViewLeft.setVisibility(View.GONE);
}
静态类NewsHolder {
TextView中了itemname;
ImageView的图标;
ImageView的imageViewLeft,imageViewRight;
RelativeLayout的mRelativeLayout;
}
解决方案
查看: SwipeActionAdapter
这是不正是你问一个伟大的图书馆。 它允许滑动在两个方向与底层布局
或颜色
。这很容易实现,看起来不错!
m trying to build android new inbox style listview with swipe left and right as shown in this image , i have tried 47deg swipelistview but its not that stable , is there any other library available?!
Tried so far with 47 deg
public class MainActivity extends Activity {
Listview pullToRefreshListView;
SwipeListView swipelistview;
ItemAdapter adapter;
List<ItemRow> itemData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pullToRefreshListView = (ListView) findViewById(R.id.example_swipe_lv_list);
swipelistview = pullToRefreshListView.getRefreshableView();
itemData = new ArrayList<ItemRow>();
adapter = new ItemAdapter(this, R.layout.custom_row, itemData);
swipelistview.setSwipeListViewListener(new BaseSwipeListViewListener() {
@Override
public void onOpened(int position, boolean toRight) {
if (toRight) {
adapter.remove(position);
Toast.makeText(MainActivity.this, "Open to dismiss",
Toast.LENGTH_SHORT).show();
} // swipelistview.dismiss(position);
else {
Toast.makeText(MainActivity.this, "Open to edit",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onClosed(int position, boolean fromRight) {
}
@Override
public void onListChanged() {
}
@Override
public void onMove(int position, float x) {
}
@Override
public void onStartOpen(int position, int action, boolean right) {
if (right) {
// adapter.onRight();
swipelistview.getChildAt(position).findViewById(R.id.back)
.setBackgroundColor(Color.GREEN);
swipelistview.getChildAt(position)
.findViewById(R.id.imageViewLeft)
.setVisibility(View.VISIBLE);
swipelistview.getChildAt(position)
.findViewById(R.id.imageViewRight)
.setVisibility(View.GONE);
} else {
// adapter.onLeft();
swipelistview.getChildAt(position).findViewById(R.id.back)
.setBackgroundColor(Color.RED);
swipelistview.getChildAt(position)
.findViewById(R.id.imageViewLeft)
.setVisibility(View.GONE);
swipelistview.getChildAt(position)
.findViewById(R.id.imageViewRight)
.setVisibility(View.VISIBLE);
}
}
@Override
public void onStartClose(int position, boolean right) {
Log.d("swipe", String.format("onStartClose %d", position));
}
@Override
public void onClickFrontView(int position) {
Log.d("swipe", String.format("onClickFrontView %d", position));
// swipelistview.openAnimate(position); //when you touch front
// view it will open
}
@Override
public void onClickBackView(int position) {
Log.d("swipe", String.format("onClickBackView %d", position));
// swipelistview.closeAnimate(position);//when you touch back
// view it will close
}
@Override
public void onDismiss(int[] reverseSortedPositions) {
}
});
// These are the swipe listview settings. you can change these
// setting as your requirement
swipelistview.setSwipeMode(SwipeListView.SWIPE_MODE_BOTH); // there are
// five
// swiping
// modes
swipelistview.setSwipeActionRight(SwipeListView.SWIPE_ACTION_REVEAL); // there
// are
// four
// swipe
// actions
swipelistview.setSwipeActionLeft(SwipeListView.SWIPE_ACTION_REVEAL);
swipelistview.setOffsetRight(convertDpToPixel(0f)); // left side
// offset
swipelistview.setOffsetLeft(convertDpToPixel(0f)); // right side
// offset
swipelistview.setAnimationTime(60); // Animation time
swipelistview.setSwipeOpenOnLongPress(false); // enable or disable
// SwipeOpenOnLongPress
swipelistview.setSwipeCloseAllItemsWhenMoveList(true);
swipelistview.setAdapter(adapter);
for (int i = 0; i < 10; i++) {
itemData.add(new ItemRow("Swipe Item" + i, getResources()
.getDrawable(R.drawable.ic_launcher)));
}
adapter.notifyDataSetChanged();
}
public int convertDpToPixel(float dp) {
DisplayMetrics metrics = getResources().getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
return (int) px;
}
}
Adapter class
public class ItemAdapter extends ArrayAdapter<ItemRow> {
List<ItemRow> data;
Context context;
int layoutResID;
public ItemAdapter(Context context, int layoutResourceId, List<ItemRow> data) {
super(context, layoutResourceId, data);
this.data = data;
this.context = context;
this.layoutResID = layoutResourceId;
// TODO Auto-generated constructor stub
}
NewsHolder holder = null;
View row = null;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
row = convertView;
holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResID, parent, false);
holder = new NewsHolder();
holder.itemName = (TextView) row
.findViewById(R.id.example_itemname);
holder.icon = (ImageView) row.findViewById(R.id.example_image);
holder.imageViewRight = (ImageView) row
.findViewById(R.id.imageViewRight);
holder.imageViewLeft = (ImageView) row
.findViewById(R.id.imageViewLeft);
row.setTag(holder);
} else {
holder = (NewsHolder) row.getTag();
}
ItemRow itemdata = data.get(position);
holder.itemName.setText(itemdata.getItemName());
holder.icon.setImageDrawable(itemdata.getIcon());
return row;
}
public void remove(int pos){
data.remove(pos);
}
public void onLeft() {
holder.imageViewLeft.setVisibility(View.VISIBLE);
holder.imageViewRight.setVisibility(View.GONE);
}
public void onRight() {
holder.imageViewRight.setVisibility(View.VISIBLE);
holder.imageViewLeft.setVisibility(View.GONE);
}
static class NewsHolder {
TextView itemName;
ImageView icon;
ImageView imageViewLeft, imageViewRight;
RelativeLayout mRelativeLayout;
}
解决方案
Check out: SwipeActionAdapter
It's a great library that does exactly what you're asking for. It allows Swipe in both directions with an underlying Layout
or Color
. It's easy to implement and looks nice!
这篇关于新的Android应用程序的收件箱列表视图风格与刷卡左,右的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!