请问有没有性价比高的西边的风儿童足膜视频?谢谢!!!

Android的RecyclerView的使用
的RecyclerView的使用
Android推出RecyclerView的时间不算短了,一直没有具体去了解。前段时间公司做代码优化,用到这个。具体了解之后发现其功能确实强大。下面来基本解释RecyclerView控件
RecyclerView干啥用的?
可以理解为效率更高的ListView和GridView,而且功能更强大。最关键的一个地方,貌似是听说在Adapter中复用之前已经产生的item,这个估计得查看内存方可以看得清楚。
使用RecyclerView,我们需要了解一下三个元素
1、RecyclerView.Adapter
2、LayoutManager
3、ItemAnimator
1、RecyclerView.Adapter
作为这么一个看起来蛮叼的控件,自然用到了各种很厉害的设计模式(这个,我不清楚)。面向接口是肯定的,那么我们来看看它的Adapter
public class MyAdapter extends RecyclerView.Adapter {
public class ViewHolder extends RecyclerView.ViewHolder {
public VideoListItem txt1;
public VideoListItem txt2;
public VideoListItem txt3;
public VideoListItem txt4;
public ViewHolder(View itemView) {
super(itemView);
public VideoListItem getTxt1() {
return txt1;
public void setTxt1(VideoListItem txt1) {
this.txt1 = txt1;
public VideoListItem getTxt2() {
return txt2;
public void setTxt2(VideoListItem txt2) {
this.txt2 = txt2;
public VideoListItem getTxt3() {
return txt3;
public void setTxt3(VideoListItem txt3) {
this.txt3 = txt3;
public VideoListItem getTxt4() {
return txt4;
public void setTxt4(VideoListItem txt4) {
this.txt4 = txt4;
private LayoutI
public MyAdapter() {
inflater = LayoutInflater.from(VideoListActivity.this);
public int getItemCount() {
int size = mVideoList.size();
if (size == 0) {
int count = mVideoList.size() / COLUMN;
if (size % COLUMN == 0) {
return count + 1;
return count + 2;
public long getItemId(int position) {
public void onBindViewHolder(ViewHolder viewHolder, int position) {
System.out.println(&wangzx**& +&onCreateViewHolder&);
int firstIndex = position * COLUMN;
int size = mVideoList.size();
bindItem(firstIndex + 0, size, position, viewHolder.txt1);
bindItem(firstIndex + 1, size, position, viewHolder.txt2);
bindItem(firstIndex + 2, size, position, viewHolder.txt3);
bindItem(firstIndex + 3, size, position, viewHolder.txt4);
private void bindItem(int index, int size, int position,
VideoListItem item) {
VideoInfo historyData0 =
if (size & index) {
item.setVisibility(View.VISIBLE);
historyData0 = mVideoList.get(index);
item.setCurrentLine(position);
item.setIndex(index);
item.setView_id(historyData0.getVideo_id());
item.getmTextView().setText(historyData0.getVideo_name());
item.getmRoundedImageView().setCornerRadiusDimen(R.dimen.video_list_corner_radius);
item.getmRoundedImageView().setImageResource(R.drawable.history_default);
imageLoader.displayImage(historyData0.getVideo_img_url(),item.getmRoundedImageView());
item.setVisibility(View.INVISIBLE);
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
System.out.println(&wangzx**& +&onCreateViewHolder&);
View convertView = inflater.inflate(R.layout.video_list_itemlist, parent,
ViewHolder viewHolder = new ViewHolder(convertView);
viewHolder.txt1 = (VideoListItem) convertView
.findViewById(R.id.item1);
viewHolder.txt2 = (VideoListItem) convertView
.findViewById(R.id.item2);
viewHolder.txt3 = (VideoListItem) convertView
.findViewById(R.id.item3);
viewHolder.txt4 = (VideoListItem) convertView
.findViewById(R.id.item4);
View itemBackground_focus1 = viewHolder.txt1.findViewById(R.id.background_focus);
View itemBackground_focus2 = viewHolder.txt2.findViewById(R.id.background_focus);
View itemBackground_focus3 = viewHolder.txt3.findViewById(R.id.background_focus);
View itemBackground_focus4 = viewHolder.txt4.findViewById(R.id.background_focus);
itemBackground_focus1.setOnFocusChangeListener(mVideoListItemOnFocus);
itemBackground_focus2.setOnFocusChangeListener(mVideoListItemOnFocus);
itemBackground_focus3.setOnFocusChangeListener(mVideoListItemOnFocus);
itemBackground_focus4.setOnFocusChangeListener(mVideoListItemOnFocus); //焦点的变换暂时不考虑在内(焦点的获取同步更新videoCount数据)
itemBackground_focus1.setOnClickListener(mOnClick);
itemBackground_focus2.setOnClickListener(mOnClick);
itemBackground_focus3.setOnClickListener(mOnClick);
itemBackground_focus4.setOnClickListener(mOnClick);
itemBackground_focus1.setOnKeyListener(mWheelKeyListener);
itemBackground_focus2.setOnKeyListener(mWheelKeyListener2);
itemBackground_focus3.setOnKeyListener(mWheelKeyListener2);
itemBackground_focus4.setOnKeyListener(mWheelKeyListener2);
return viewH
图RecyclerView
public class Byhistory__Adapater extends BaseAdapter {
private ArrayList
private LayoutInflater mI
public Byhistory__Adapater(Context context,ArrayList byhistory_list){
this.byhistorylist = byhistory_
this.mInflater = LayoutInflater.from(context);
public int getCount() {
return this.byhistorylist.size();
public Object getItem(int arg0) {
public long getItemId(int arg0) {
public View getView(int position, View convertView, ViewGroup arg2) {
Byhistory_I
if(convertView == null){
convertView = mInflater.inflate(R.layout.byhistory_item, null);
holder = new Byhistory_Item();
holder.setLayout_Image((ImageView) convertView.findViewById(R.id.history_item_image));
holder.setLayout_ID((TextView) convertView.findViewById(R.id.history_item_name));
holder.setLayout_price((TextView) convertView.findViewById(R.id.history_item_price));
holder.setLayout_count((TextView) convertView.findViewById(R.id.history_item_count));
holder.setLayout_business((ImageView) convertView.findViewById(R.id.history_item_more));
convertView.setTag(holder);
holder = (Byhistory_Item) convertView.getTag();
Byhistory_Item dd = byhistorylist.get(position);
holder.getLayout_Image().setBackgroundResource(Integer.valueOf(dd.getItem_Tile_Image()));
holder.getLayout_ID().setText(dd.getItem_Title_ID());
holder.getLayout_price().setText(dd.getItem_price());
holder.getLayout_count().setText(dd.getItem_count());
holder.getLayout_business().setBackgroundResource(Integer.valueOf(dd.getItem_business()));
return convertV
图ListView
对比listview的adapater我们立马就能看出来。这里它单独弄出来了一个ViewHolder。这个ViewHolder可以是多个layout的组合,这样做更加灵活,使得布局更加多变(可以仔细想一下是为什么)。
ListView的Adapter通常是直接导入数据,下滑。但是RecyclerView的Adapter就不是下滑这么简单,上下滑动和左右滑动都成为可能。这个关键就是LayoutManager的功劳了。配合ViewHolder的多样性,功能真是很强大。
2、LayoutManager
知道android貌似确实是有不止一种LayoutManager,但是其他的没有接触过,暂就不发表评论,以后可能会补充
LinearLayoutManager
public class MyLinearLayoutManager extends LinearLayoutManager {
public MyLinearLayoutManager(Context context) {
super(context);
public MyLinearLayoutManager(Context context, int orientation,
boolean reverseLayout) {
super(context, orientation, reverseLayout);
public boolean requestChildRectangleOnScreen(RecyclerView parent,
View child, Rect rect, boolean immediate) {
final int parentLeft = getPaddingLeft();
final int parentTop = getPaddingTop();
final int parentRight = getWidth() - getPaddingRight();
final int parentBottom = getHeight() - getPaddingBottom();
final int childLeft = child.getLeft() + rect.
final int childTop = child.getTop() + rect.
final int childRight = childLeft + rect.
final int childBottom = childTop + rect.
final int offScreenLeft = Math.min(0, childLeft - parentLeft);
final int offScreenTop = Math.min(0, childTop - parentTop);
final int offScreenRight = Math.max(0, childRight - parentRight);
final int offScreenBottom = Math.max(0, childBottom - parentBottom);
// Favor the &start& layout direction over the end when bringing one
// side or the other
// of a large rect into view.
if (ViewCompat.getLayoutDirection(parent) == ViewCompat.LAYOUT_DIRECTION_RTL) {
dx = offScreenRight != 0 ? offScreenRight : offScreenL
dx = offScreenLeft != 0 ? offScreenLeft : offScreenR
// Favor bringing the top into view over the bottom
int dy = offScreenTop != 0 ? offScreenTop : offScreenB
if (dy & 0) {
//偏移量是40,焦点计算的高是360,比整体高少40,原因是焦点的view是item的子View,item的高度是400
dy += 400;
if (dy & 0) {
dy -= 400;
if (dx != 0 || dy != 0) {
if (immediate) {
parent.scrollBy(dx, dy);
parent.smoothScrollBy(dx, dy);
public int scrollHorizontallyBy(int dx, Recycler recycler, State state) {
public boolean requestChildRectangleOnScreen(RecyclerView parent,
View child, Rect rect, boolean immediate)函数是相当重要的,它基本就能够确定在布局中滚动或者滑动时候,子Item和parent之间的位置。仔细查看这个函数的父类我们可以知道,dy,dx的实际意义就是在滚动中下滑和左右滑动的距离。而这个值的确定会严重影响滑动的流畅程度(我一直在调试这两个值&&)
public int scrollHorizontallyBy(int dx, Recycler recycler, State state)这个函数是滑动中的回调函数。见到的人肯定很多,不足为奇。
3、ItemAnimator
是滑动进行中的动画,听别人说很炫,但是自己貌似没有亲手去实现,知道有这么个东西而已吧。
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'Android L——RecyclerView,CardView的导入和使用
本文主要介绍Android L新增加的两个UI控件RecyclerView,CardView的导入和使用。
RecyclerView:ListView的升级版,它提供了更好的性能而且更容易使用。该控件是一个可以装载大量的视图集合,并且可以非常效率的进行回收和滚动。当你list中的元素经常动态改变时可以使用RecyclerView控件。它提供了如下两个功能:
1、为每个条目位置提供了layout管理器(RecyclerView.setLayoutManager)
2、为每个条目设置了操作动画(RecyclerView.setItemAnimator)
CardView:Google提供的一个卡片式视图组件。CardView继承自FrameLayout,允许你在Card视图中显示信息, CardView也可以设置阴影和圆角。(其实现在很多应用都自定义了Card视图,Google这回将Card视图作为基本控件,可以拿来直接使用了。)
本例就是一个使用RecyclerView来展示多个CardView的一个小例子,先看下效果图:
导入RecyclerView,CardView
由于RecyclerView,CardView是放在support library v7包中,所以我们想要使用就必须要导包。
下面就介绍下在Eclipse和Android Studio中是如何导入这两个包的。
第一步:通过SDK manager下载/更新Android Support Libraries(5.0版本最新为21)&
第二步:导入CardView和RecyclerView项目(都在support v7中)
1、在Eclipse中点击Import,导入Android项目
2、导入CardView和RecycleView,路径为your sdk path\extras\android\support\v7\cardview(RecycleView则为相同目录下的recyclerview)
3、导入时记得将工程copy到本地并建议重命名,这样方便以后管理例如:
第三步:设置Library
1、将两个工程设置为Library
2、在主工程中引入这两个Library例如:
通过这三步就可以将这两个包导入进来了。
Android Studio
Android Stuido相对于Eclipse简单的多。
第一步:首先要确保已经将Android Support Libraries升级到最新。
第二步:打开项目中的build.gradle文件,在dependencies中添加如下代码。
dependencies&{
&&&&compile&'com.android.support:recyclerview-v7:21.+'
&&&&compile&'com.android.support:cardview-v7:21.+'
第三步:重新Build一下工程,Build完成后就会发现这两个包就已经导入进来了。
代码介绍:
首先这个黑色基调的主题是使用了Material.Dark.ActionBar样式。
设置方法:修改values-v21文件夹下styles.xml文件:
&resources&&&
&&&&&style&name="AppTheme"&parent="android:ThemeOverlay.Material.Dark.ActionBar"&&&
&&&&&/style&&&
&/resources&
布局文件:
recycler_view.xml(RecyclerView布局文件):
&?xml&version="1.0"&encoding="utf-8"?&&&
&FrameLayout&xmlns:android=""&&
&&&&xmlns:tools=""&&
&&&&android:layout_width="match_parent"&&
&&&&android:layout_height="match_parent"&&
&&&&tools:context=".MyActivity"&&&
&&&&&android.support.v7.widget.RecyclerView&&
&&&&&&&&android:id="@+id/list"&&
&&&&&&&&android:layout_width="match_parent"&&
&&&&&&&&android:layout_height="match_parent"&&
&&&&&&&&tools:context=".MyActivity"&/&&&
&/FrameLayout&
FrameLayout里包含了RecyclerView控件。
card_view.xml(CardView布局文件):
&android.support.v7.widget.CardView&xmlns:android=""&&
&&&&xmlns:card_view=""&&
&&&&android:layout_width="match_parent"&&
&&&&android:layout_height="match_parent"&&
&&&&android:layout_margin="5dp"&&
&&&&android:orientation="horizontal"&&
&&&&card_view:cardBackgroundColor="@color/cardview_dark_background"&&
&&&&card_view:cardCornerRadius="5dp"&&&&
&&&&&RelativeLayout&&
&&&&&&&&android:layout_width="match_parent"&&
&&&&&&&&android:layout_height="100dp"&&
&&&&&&&&android:padding="5dp"&&&&
&&&&&&&&&ImageView&&
&&&&&&&&&&&&android:id="@+id/pic"&&
&&&&&&&&&&&&android:layout_width="match_parent"&&
&&&&&&&&&&&&android:layout_height="match_parent"&&
&&&&&&&&&&&&android:layout_centerInParent="true"&&
&&&&&&&&&&&&android:scaleType="centerCrop"&/&&&
&&&&&&&&&TextView&&
&&&&&&&&&&&&android:clickable="true"&&
&&&&&&&&&&&&android:id="@+id/name"&&
&&&&&&&&&&&&android:layout_width="match_parent"&&
&&&&&&&&&&&&android:layout_height="match_parent"&&
&&&&&&&&&&&&android:layout_marginBottom="10dp"&&
&&&&&&&&&&&&android:layout_marginRight="10dp"&&
&&&&&&&&&&&&android:gravity="right|bottom"&&
&&&&&&&&&&&&android:textColor=" :color/white"&&
&&&&&&&&&&&&android:textSize="24sp"&/&&&
&&&&&/RelativeLayout&&&
&/android.support.v7.widget.CardView&
CardView视图中包含了一个ImageView和一个TextView分别显示图片和文字信息。
唯一需要介绍的就是在布局文件中使用了,如下两个属性:
card_view:cardBackgroundColor="@color/cardview_dark_background"&&
&&&card_view:cardCornerRadius="5dp"
他俩的作用分别是设置CardView的背景颜色和外围的圆角大小(注意要使用card_view命名空间)
Actor类(封装数据的Model类):
public&class&Actor
&&&&String&
&&&&String&picN
&&&&public&Actor(String&name,&String&picName)
&&&&&&&&this.name&=&
&&&&&&&&this.picName&=&picN
&&&&public&int&getImageResourceId(&Context&context&)
&&&&&&&&try
&&&&&&&&&&&&return&context.getResources().getIdentifier(this.picName,&"drawable",&context.getPackageName());
&&&&&&&&catch&(Exception&e)
&&&&&&&&&&&&e.printStackTrace();
&&&&&&&&&&&&return&-1;
封装了演员的名字和图片名,getImageResourceId()方法的作用就是根据图片命找到系统资源。
MyActivity(程序主控制Activity)
public&class&MyActivity
&&&&extends&Activity
&&&&private&RecyclerView&mRecyclerV
&&&&private&MyAdapter&myA
&&&&private&Listactors&=&new&ArrayList();
&&&&private&String[]&names&=&{&"朱茵",&"张柏芝",&"张敏",&"巩俐",&"黄圣依",&"赵薇",&"莫文蔚",&"如花"&};
&&&&private&String[]&pics&=&{&"p1",&"p2",&"p3",&"p4",&"p5",&"p6",&"p7",&"p8"&};
&&&&@Override
&&&&protected&void&onCreate(&Bundle&savedInstanceState&)
&&&&&&&&super.onCreate(savedInstanceState);
&&&&&&&&setContentView(R.layout.recycler_view);
&&&&&&&&actors.add(new&Actor("朱茵",&"p1"));
&&&&&&&&getActionBar().setTitle("那些年我们追的星女郎");
&&&&&&&&//&拿到RecyclerView
&&&&&&&&mRecyclerView&=&(RecyclerView)&findViewById(R.id.list);
&&&&&&&&//&设置LinearLayoutManager
&&&&&&&&mRecyclerView.setLayoutManager(new&LinearLayoutManager(this));
&&&&&&&&//&设置ItemAnimator
&&&&&&&&mRecyclerView.setItemAnimator(new&DefaultItemAnimator());
&&&&&&&&//&设置固定大小
&&&&&&&&mRecyclerView.setHasFixedSize(true);
&&&&&&&&//&初始化自定义的适配器
&&&&&&&&myAdapter&=&new&MyAdapter(this,&actors);
&&&&&&&&//&为mRecyclerView设置适配器
&&&&&&&&mRecyclerView.setAdapter(myAdapter);
&&&&@Override
&&&&public&boolean&onCreateOptionsMenu(Menu&menu)&{
&&&&&&&&getMenuInflater().inflate(R.menu.menu,&menu);
&&&&&&&&return&
&&&&@Override
&&&&public&boolean&onOptionsItemSelected(MenuItem&item)&{
&&&&&&&&switch(item.getItemId())&{
&&&&&&&&&&&&//&当点击actionbar上的添加按钮时,向adapter中添加一个新数据并通知刷新
&&&&&&&&&&&&case&R.id.action_add:
&&&&&&&&&&&&&&&&if&(myAdapter.getItemCount()&!=&names.length)&{
&&&&&&&&&&&&&&&&&&&&actors.add(new&Actor(names[myAdapter.getItemCount()],&pics[myAdapter.getItemCount()]));
&&&&&&&&&&&&&&&&&&&&mRecyclerView.scrollToPosition(myAdapter.getItemCount()&-&1);
&&&&&&&&&&&&&&&&&&&&myAdapter.notifyDataSetChanged();
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&return&
&&&&&&&&&&&&//&当点击actionbar上的删除按钮时,向adapter中移除最后一个数据并通知刷新
&&&&&&&&&&&&case&R.id.action_remove:
&&&&&&&&&&&&&&&&if&(myAdapter.getItemCount()&!=&0)&{
&&&&&&&&&&&&&&&&&&&&actors.remove(myAdapter.getItemCount()-1);
&&&&&&&&&&&&&&&&&&&&mRecyclerView.scrollToPosition(myAdapter.getItemCount()&-&1);
&&&&&&&&&&&&&&&&&&&&myAdapter.notifyDataSetChanged();
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&return&
&&&&&&&&return&super.onOptionsItemSelected(item);
MyAdapter(自定义适配器类)
public&class&MyAdapter
&&&&extends&RecyclerView.Adapter{
&&&&private&L
&&&&private&Context&mC
&&&&public&MyAdapter(&Context&context&,&Listactors)
&&&&&&&&this.mContext&=&
&&&&&&&&this.actors&=&
&&&&@Override
&&&&public&ViewHolder&onCreateViewHolder(&ViewGroup&viewGroup,&int&i&)
&&&&&&&&//&给ViewHolder设置布局文件
&&&&&&&&View&v&=&LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_view,&viewGroup,&false);
&&&&&&&&return&new&ViewHolder(v);
&&&&@Override
&&&&public&void&onBindViewHolder(&ViewHolder&viewHolder,&int&i&)
&&&&&&&&//&给ViewHolder设置元素
&&&&&&&&Actor&p&=&actors.get(i);
&&&&&&&&viewHolder.mTextView.setText(p.name);
&&&&&&&&viewHolder.mImageView.setImageDrawable(mContext.getDrawable(p.getImageResourceId(mContext)));
&&&&@Override
&&&&public&int&getItemCount()
&&&&&&&&//&返回数据总数
&&&&&&&&return&actors&==&null&?&0&:&actors.size();
&&&&//&重写的自定义ViewHolder
&&&&public&static&class&ViewHolder
&&&&&&&&extends&RecyclerView.ViewHolder
&&&&&&&&public&TextView&mTextV
&&&&&&&&public&ImageView&mImageV
&&&&&&&&public&ViewHolder(&View&v&)
&&&&&&&&&&&&super(v);
&&&&&&&&&&&&mTextView&=&(TextView)&v.findViewById(R.id.name);
&&&&&&&&&&&&mImageView&=&(ImageView)&v.findViewById(R.id.pic);
以上所有代码就介绍完了,可以总结为以下两点:
RecyclerView:
理解为之前的ListView,不过需要设置LinearLayoutManager和ItemAnimator两个新属性。
RecyclerView.Adapter:
理解为默认自带和基于ViewHolder的新的适配器,只不过回调方法稍有不同,但本质都是一样的。
推荐阅读:
&来一篇偏技术点的, 希望能对大家有些许帮助
写的非常好,但是目前React Native开发越来越火
微信小程序是基于React Native开发的,体验接近原生APP,发展前景值得重视
我分享个项目:微信电影预订_微信小程序
源代码下载(百度网盘):&&
功能包括:已上映电影列表,搜索附近电影院,电影评分等功能
这个不错,UI设计标准,代码比较规范,很好的学习范例

我要回帖

更多关于 footner 去角质足膜 的文章

 

随机推荐