android 左右卡片切换,3D卡片切换

源码片段

public class MainActivity extends FragmentActivity implements OnCardClickListener{

List list;

private TestFragment frag;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

initUI();

}

private void initUI() {

CardView cardView = (CardView) findViewById(R.id.cardView1);

cardView.setOnCardClickListener(this);

cardView.setItemSpace(Utils.convertDpToPixelInt(this, 20));

MyCardAdapter adapter = new MyCardAdapter(this);

adapter.addAll(initData());

cardView.setAdapter(adapter);

FragmentManager manager = getSupportFragmentManager();

frag = new TestFragment();

manager.beginTransaction().add(R.id.contentView, frag).commit();

}

@Override

public void onCardClick(final View view, final int position) {

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

Bundle bundle = new Bundle();

bundle.putString("text", list.get(position%list.size()));

frag.show(view,bundle);

}

private List initData() {

list = new ArrayList();

list.add("a");

list.add("b");

list.add("c");

list.add("d");

list.add("e");

list.add("f");

list.add("g");

return list;

}

public class MyCardAdapter extends CardAdapter{

public MyCardAdapter(Context context) {

super(context);

}

@Override

public int getCount() {

return Integer.MAX_VALUE;

}

@Override

protected View getCardView(int position,

View convertView, ViewGroup parent) {

if(convertView == null) {

LayoutInflater inflater = LayoutInflater.from(MainActivity.this);

convertView = inflater.inflate(R.layout.item_layout, parent, false);

}

TextView tv = (TextView) convertView.findViewById(R.id.textView1);

String text = getItem(position%list.size());

tv.setText(text);

return convertView;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值