RecyclerView and CardView

android.support.v7.widget.RecyclerView

android.support.v7.widget.CardView

RecyclerView使用时需要 adapter 和 layout manager

adapter extends RecyclerView.Adapter 

layout manager extends RecyclerView.LayoutManager

animations extends RecyclerView.ItemAnimator() 使用setItemAnimator()

public class Myadapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>{
	private String[] mDataset;

	public static class viewHolder extends RecyclerView.ViewHolder{
		public TextView mTextView;
		public ViewHolder(TextView v){
			super(v);
			mTextView = v;
		}
	}

	public MyAdapter(String[] myDataset){
		mDataset = myDataset;
	}

	public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,int viewType){
		View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.my_text_view,parent,false);
		//...
		ViewHolder vh = new ViewHolder(v);
		return vh;
	}

	public void onBindViewHolder(ViewHolder holder,int position){
		holder.mTextView.setText(mDataset[positioni]);
	}

	public int getItemCount(){
		return mDataset.length;
	}
}


dependencies {
    ...
    compile 'com.android.support:cardview-v7:+'
    compile 'com.android.support:recyclerview-v7:+'
}


CardView extends FrameLayout
card_view:cardCornerRadius  <--> CardView.setRadius

card_view:cardBackgroundColor 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    ... >
    <!-- A CardView that contains a TextView -->
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="200dp"
        android:layout_height="200dp"
        card_view:cardCornerRadius="4dp">

        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v7.widget.CardView>
</LinearLayout>








android.support.v7.widget.CardView
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值