RecylerView 的使用方法
package com.cardvalue.sys.fragment; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; import com.bartoszlipinski.recyclerviewheader.RecyclerViewHeader;
import com.cardvalue.sys.activity.LoadWebPage;
import com.cardvalue.sys.R;
import com.cardvalue.sys.adapter.MoreRecylerAdapter;
import com.cardvalue.sys.base.BaseFragment;
import com.cardvalue.sys.entity.MoreListDto;
import com.cardvalue.sys.newnetwork.Config; import java.util.ArrayList;
import java.util.List; import butterknife.Bind;
import butterknife.ButterKnife; /**
* Recyler来取代listview 很多其它页面
* Created by cardvalue on 2016/4/5.
*/
public class MoreRecylerFragment extends BaseFragment {
String server = Config.getWeixinIp()+"";
private View view;
@Bind(R.id.recyclerView) RecyclerView recyclerView;
<span style="color:#cc0000;">@Bind(R.id.header) RecyclerViewHeader header;</span>
private List<MoreListDto> mMoreListDto= new ArrayList<>();
private MoreRecylerAdapter mMoreAdapter;
private int [] icons={R.mipmap.share,R.mipmap.pruoduce,R.mipmap.honor,
R.mipmap.contact,R.mipmap.about,R.mipmap.feedback,R.mipmap.service,R.mipmap.service};
private String[] title={"融资攻略","公司简单介绍","资质荣誉","联系方式","关于小企额","意见反馈","在线客服"}; private String[] activity={"","","","","com.cardvalue.sys.activity.AboutActivity",
"com.cardvalue.sys.activity.FeedBackActivity","com.cardvalue.sys.activity.CustomerServiceActivity"};
String url1=server+"new/m/more/question";
String url2=server+"/new/m/more/aboutUs? isApp=1";
String url3=server+"/new/m/more/honor?isApp=1";
String url4=server+"/new/m/more/contactUs?isApp=1"; private String[] url={url1,url2,url3,url4,"","",""};
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view=inflater.inflate(R.layout.fragment_more_recyler,container,false);
ButterKnife.bind(this,view);
// 创建一个线性布局管理器
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(<span style="color:#cc0000;">LinearLayoutManager.VERTICAL</span>);<span style="color:#ff0000;">//设置垂直 还是水平</span>
// 设置布局管理器
recyclerView.setLayoutManager(layoutManager);
<span style="color:#990000;"> </span><span style="color:#cc0000;"> header.attachTo(recyclerView, true);//加入header</span> view.findViewById(R.id.as).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction("android.intent.action.CALL");
intent.addCategory("android.intent.category.DEFAULT");
//指定要拨打的电话号码
intent.setData(Uri.parse("tel:" + "4008-803-803"));
startActivity(intent);
}
}); for(int i=0;i<title.length;i++){
MoreListDto item=new MoreListDto();
item.setTitle(title[i]);
item.setIconIndex(icons[i]);
item.setActivity(activity[i]);
item.setUrl(url[i]);
if (i == 0 || i == 1) {
item.setShow(true);
}
mMoreListDto.add(item);
}
<span style="color:#cc0000;"> mMoreAdapter = new MoreRecylerAdapter(getActivity(),mMoreListDto);
recyclerView.setAdapter(mMoreAdapter);</span>
mMoreAdapter.setItemClickListener(new MoreRecylerAdapter.OnItemClickListener() {
@Override
public void onItemClick(View v, int position) {
// MoreListDto item=(MoreListDto)mListView.getItemAtPosition(position);
MoreListDto item =mMoreListDto.get(position);
if(!item.getActivity().equals("")){
try {
Intent intent = new Intent(getActivity(),Class.forName(item.getActivity().toString()));
startActivity(intent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}else if(!item.getUrl().equals("")){
Intent intent = new Intent(getActivity(),LoadWebPage.class);
intent.putExtra("title", item.getTitle().toString());
intent.putExtra("url", item.getUrl().toString());
startActivity(intent);
}
}
}); return view;
} @Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
setHeaderFields(0, R.string.more,0,0, 0,0);
super.onActivityCreated(savedInstanceState);
} }
<pre name="code" class="java">package com.cardvalue.sys.adapter; import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView; import com.cardvalue.sys.R;
import com.cardvalue.sys.entity.MoreListDto; import java.util.ArrayList;
import java.util.List; /**
* 很多其它页面的adapter
* Created by cardvalue on 2016/4/1.
*/
public class MoreRecylerAdapter extends RecyclerView.Adapter{
private List<MoreListDto> mMoreListDto= new ArrayList<>();
private Context context;
private LayoutInflater inflater;
public MoreRecylerAdapter(Context context, List<MoreListDto> mMoreListDto){//Context context,
this.context=context;
this.mMoreListDto=mMoreListDto;
this.inflater=LayoutInflater.from(context);
} @Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = View.inflate(context,R.layout.list_more,null);
return new ViewHolder(view);
} @Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if(holder instanceof ViewHolder){
ViewHolder viewHolder=(ViewHolder)holder;
MoreListDto moreListDto =mMoreListDto.get(position) ;
if(moreListDto!=null){
if(moreListDto.isShow()){
viewHolder.asd.setVisibility(View.VISIBLE);
}else{
viewHolder.asd.setVisibility(View.GONE);
} if(moreListDto.getTitle().equals("融资攻略")||moreListDto.getTitle().equals("在线客服")){
viewHolder.bottom.setVisibility(View.VISIBLE);
}
viewHolder.image1.setImageResource(moreListDto.getIconIndex());
viewHolder.text1.setText(moreListDto.getTitle());
}
}
} @Override
public int getItemCount() {
return mMoreListDto!=null?mMoreListDto.size():0;
} class ViewHolder extends RecyclerView.ViewHolder{
ImageView image1;
TextView text1;
RelativeLayout root;
View asd;
View bottom; public ViewHolder(View itemView) {
super(itemView);
init(itemView);
//给列表item点击点击事件
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(itemClickListener!=null){
itemClickListener.onItemClick(v,getLayoutPosition());
}
}
}); } private void init(View view){
image1 = (ImageView) view.findViewById(R.id.image1);
text1 = (TextView) view.findViewById(R.id.text1);
root = (RelativeLayout) view.findViewById(R.id.root);
asd= view.findViewById(R.id.and);
bottom= view.findViewById(R.id.bottom);
}
} //对外部暴漏点击事件接口
public interface OnItemClickListener{
void onItemClick(View v,int position);
} public OnItemClickListener itemClickListener; public void setItemClickListener(OnItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
} }
<?xml version="1.0" encoding="utf-8"? >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/background_color"
tools:context="com.cardvalue.sys.fragment.BasicFragment">
<include android:id="@+id/include_title" layout="@layout/include_title"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"> <android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="horizontal" /> <com.bartoszlipinski.recyclerviewheader.RecyclerViewHeader
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/as"
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="@color/white" > <ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="76dp"
android:layout_marginTop="20dp"
android:layout_centerVertical="true"
android:src="@mipmap/service1" /> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/imageView1"
android:gravity="center_vertical"
android:orientation="vertical" > <TextView
android:id="@+id/aa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:text="@string/phone"
android:textColor="#010101"
android:textSize="17sp" /> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:text="@string/time"
android:textColor="#606060"
android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
<View
style="@style/lines_dbdbdb" />
</LinearLayout>
</com.bartoszlipinski.recyclerviewheader.RecyclerViewHeader>
</FrameLayout>
</LinearLayout>
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.bartoszlipinski.recyclerviewheader:library:1.2.0' 加入header
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.facebook.fresco:fresco:0.9.0+'
compile 'io.reactivex:rxjava:1.1.2'
compile 'io.reactivex:rxandroid:1.1.0'
compile files('libs/fraudmetrix-2.0.5.jar')
compile files('libs/locSDK_6.03.jar')
RecylerView 的使用方法的更多相关文章
- 完整的RecylerView的使用方法和例子
一.RecylerView的特点 1. 不关心Item是否显示在正确的位置,通过设置不同LayoutManager 的实例让Item显示不同的风格. 2. 不关心 Item间如何分离.要定义It ...
- 两种图片下拉放大效果实现(自定义CoordinatorLayout以及自定义Recylerview)
一.自定义CoordinatorLayout实现图片放大功能 本文是基于折叠布局实现的图片上拉滑动,下拉图片放大,松手放大的效果,先看下效果图. 实现原理: 1.使用CoordinatorLayout ...
- Android RecyclerView 使用解析
RecyclerView出现已经有一段时间了,相信大家肯定不陌生了,大家能够通过导入support-v7对其进行使用. 据官方的介绍,该控件用于在有限的窗体中展示大量数据集.事实上这样功能的控件我们 ...
- 打造Android万能上拉下拉刷新框架--XRefreshView(三)
转载请注明出处:http://blog.csdn.net/footballclub/ 打造Android万能上拉下拉刷新框架–XRefreshView(一) 打造Android万能上拉下拉刷新框架–X ...
- 每日一问:谈谈对 MeasureSpec 的理解
作为一名 Android 开发,正常情况下对 View 的绘制机制基本还是耳熟能详的,尤其对于经常需要自定义 View 实现一些特殊效果的同学. 网上也出现了大量的 Blog 讲 View 的 onM ...
- javaSE27天复习总结
JAVA学习总结 2 第一天 2 1:计算机概述(了解) 2 (1)计算机 2 (2)计算机硬件 2 (3)计算机软件 2 (4)软件开发(理解) 2 (5) ...
- 安卓开发笔记(十):升级ListView为RecylerView的使用
概述 RecyclerView是什么 从Android 5.0开始,谷歌公司推出了一个用于大量数据展示的新控件RecylerView,可以用来代替传统的ListView,更加强大和灵活.Recycle ...
- XamarinAndroid组件教程RecylerView适配器设置动画示例
XamarinAndroid组件教程RecylerView适配器设置动画示例 [示例1-3]下面将在RecylerView的子元素进行滚动时,使用适配器动画.具体的操作步骤如下: (1)创建一个名为R ...
- XamarinAndroid组件教程RecylerView适配器设置动画
XamarinAndroid组件教程RecylerView适配器设置动画 本小节将讲解动画相关设置,如动画的时长.插值器以及复合动画等. 1.设置动画时长 设置动画持续的时间可以使用Animation ...
随机推荐
- yii源码一 -- CComponent
CComponent: path:framework/base/CComponent.php overview:This file contains the foundation classes fo ...
- Android Studio中关于9-patch格式图片的编译错误
最近在编译Android Studio开发的项目中在使用了9宫图后出现了编译错误,尝试了多种方法未能解决,最后仔细查看出错的日志发现,居然是图片的原因,图片中包含有alpah通道所以在执行app:me ...
- Mina.Net实现的UDP协议消息收发Demo
using Mina.Filter.Codec; using Mina.Filter.Codec.TextLine; using System; using System.Collections.Ge ...
- 运用BufferedWriter把数据写入文件
public class WriteReadFiles { private static Logger log = LoggerFactory.getLogger(WriteReadFiles.cla ...
- 禁用系统的Ctrl+Alt+Left/Right(方向键)
对于非常多工具,如IntelliJ IDE,Ctrl+Alt+Left/Right(方向键)是一个非常重要的快捷键,可是这个快捷键经常会被一些显示相关的附属应用给占用用于调整屏幕显示的朝向,有时候即使 ...
- C++库研究笔记--用__attribute__((deprecated)) 管理过时代码
用__attribute__((deprecated)) 管理过时代码.同一时候保留兼容的接口 Linux下: #define DEPR_AFTER __attribute__((deprecated ...
- intellij 创建测试
之后再test目录下面创建java的文件夹,悲催的发现不能创建.想了好久,之后找到再本机的目录,手动创建java文件夹,然后点击test文件夹 ,并且点击下面的Tests文件夹 设置完test-> ...
- Android——代码中使用颜色值
android中设置颜色时,可以直接使用颜色值来设置: view.setBackgroundColor(Color.parseColor("#颜色值"));
- Dubbo源码解读:appendAnnotation [01]
import java.lang.reflect.Method; public class AppendAnnotation { /** * 获取某个Annotation实例的所有方法值(实际是Ann ...
- Tomcat 的 JDBC 连接池
JDBC 连接池 org.apache.tomcat.jdbc.pool 是 Apache Commons DBCP 连接池的一种替换或备选方案. 那究竟为何需要一个新的连接池? 原因如下: Comm ...