第一布局
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="com.example.dfx.MainActivity">
//侧滑栏
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/draw"
>
//策划栏内的布局
<RelativeLayout
android:id="@+id/rel"
android:layout_gravity="start"
android:layout_width="200dp"
android:layout_height="match_parent"
android:background="#ff0"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:id="@+id/img"/>
<ListView
android:layout_below="@id/img"
android:layout_width="match_parent"
android:id="@+id/lv"
android:layout_height="wrap_content"></ListView>
</RelativeLayout>
//主页面
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
>
<Button
android:id="@+id/b1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="首页"
android:onClick="b1"
android:textSize="18dp"
/>
<Button
android:id="@+id/b2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="想法"
android:onClick="b2"
android:textSize="18dp"
/>
<Button
android:id="@+id/b3"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="市场"
android:onClick="b3"
android:textSize="18dp"
/>
<Button
android:id="@+id/b4"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="通知"
android:onClick="b4"
android:textSize="18dp"
/>
<Button
android:id="@+id/b5"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="更多"
android:onClick="b5"
android:textSize="18dp"
/>
</LinearLayout>
<FrameLayout
android:id="@+id/fl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/ll"
></FrameLayout>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
//第一actitvity
private Button b1;
private Button b2;
private Button b3;
private Button b4;
private Button b5;
private Fragment1 fragment1;
private Fragment2 fragment2;
private Fragment3 fragment3;
private Fragment4 fragment4;
private Fragment5 fragment5;
private ListView listView;
private DrawerLayout drawerLayout;
private RelativeLayout rel;
private List<String> datas;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(MainActivity.this,"现在的网络状态是"+Wlj.getNetype(this),Toast.LENGTH_SHORT).show();
initView();
initFragment();
Draw();
}
private void Draw() {
drawerLayout = (DrawerLayout) findViewById(R.id.draw);
listView = (ListView) findViewById(R.id.lv);
rel = (RelativeLayout) findViewById(R.id.rel);
//构造数据
datas = new ArrayList<String>();
datas.add("个人设置");
datas.add("缓存");
datas.add("夜间模式");
datas.add("配置");
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, datas);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//关闭侧滑菜单
drawerLayout.closeDrawer(rel);
//drawerLayout.openDrawer(rel);//打开侧滑菜单
//设置参数
ContentFragment contentFragment=new ContentFragment();
Bundle bundle=new Bundle();
bundle.putString("value",datas.get(position));
contentFragment.setArguments(bundle);
//切换fragment
getSupportFragmentManager().beginTransaction().replace(R.id.fl,contentFragment).commit();
}
});
drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
//slideOffset:侧滑菜单 宽度的像素值
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
@Override
public void onDrawerOpened(View drawerView) {
Log.d("zzz","open");
}
@Override
public void onDrawerClosed(View drawerView) {
Log.d("zzz","close");
}
@Override
public void onDrawerStateChanged(int newState) {
Log.d("zzz","状态改变:"+newState);
}
});
}
//控件初始化
private void initView() {
b1 = (Button) findViewById(R.id.b1);
b2 = (Button) findViewById(R.id.b2);
b3= (Button) findViewById(R.id.b3);
b4 = (Button) findViewById(R.id.b4);
b5 = (Button) findViewById(R.id.b5);
b1.setTextColor(Color.RED);
}
private void initFragment() {
fragment1 = new Fragment1();
fragment2 = new Fragment2();
fragment3 = new Fragment3();
fragment4 = new Fragment4();
fragment5 = new Fragment5();
getSupportFragmentManager().beginTransaction().add(R.id.fl, fragment1).commit();
getSupportFragmentManager().beginTransaction().add(R.id.fl, fragment2).commit();
getSupportFragmentManager().beginTransaction().add(R.id.fl, fragment3).commit();
getSupportFragmentManager().beginTransaction().add(R.id.fl, fragment4).commit();
getSupportFragmentManager().beginTransaction().add(R.id.fl, fragment5).commit();
getSupportFragmentManager().beginTransaction().hide(fragment1).commit();
getSupportFragmentManager().beginTransaction().hide(fragment2).commit();
getSupportFragmentManager().beginTransaction().hide(fragment3).commit();
getSupportFragmentManager().beginTransaction().hide(fragment4).commit();
getSupportFragmentManager().beginTransaction().hide(fragment5).commit();
getSupportFragmentManager().beginTransaction().show(fragment1).commit();
}
public void b1(View view) {
b1.setTextColor(Color.RED);
b2.setTextColor(Color.BLACK);
b3.setTextColor(Color.BLACK);
b4.setTextColor(Color.BLACK);
b5.setTextColor(Color.BLACK);
getSupportFragmentManager().beginTransaction().show(fragment1).commit();
getSupportFragmentManager().beginTransaction().hide(fragment2).commit();
getSupportFragmentManager().beginTransaction().hide(fragment3).commit();
getSupportFragmentManager().beginTransaction().hide(fragment4).commit();
getSupportFragmentManager().beginTransaction().hide(fragment5).commit();
}
public void b2(View view) {
b1.setTextColor(Color.BLACK);
b2.setTextColor(Color.RED);
b3.setTextColor(Color.BLACK);
b4.setTextColor(Color.BLACK);
b5.setTextColor(Color.BLACK);
getSupportFragmentManager().beginTransaction().hide(fragment1).commit();
getSupportFragmentManager().beginTransaction().show(fragment2).commit();
getSupportFragmentManager().beginTransaction().hide(fragment3).commit();
getSupportFragmentManager().beginTransaction().hide(fragment4).commit();
getSupportFragmentManager().beginTransaction().hide(fragment5).commit();
}
public void b3(View view) {
b1.setTextColor(Color.BLACK);
b2.setTextColor(Color.BLACK);
b3.setTextColor(Color.RED);
b4.setTextColor(Color.BLACK);
b5.setTextColor(Color.BLACK);
getSupportFragmentManager().beginTransaction().hide(fragment1).commit();
getSupportFragmentManager().beginTransaction().hide(fragment2).commit();
getSupportFragmentManager().beginTransaction().show(fragment3).commit();
getSupportFragmentManager().beginTransaction().hide(fragment4).commit();
getSupportFragmentManager().beginTransaction().hide(fragment5).commit();
}
public void b4(View view) {
b1.setTextColor(Color.BLACK);
b2.setTextColor(Color.BLACK);
b3.setTextColor(Color.BLACK);
b4.setTextColor(Color.RED);
b5.setTextColor(Color.BLACK);
getSupportFragmentManager().beginTransaction().hide(fragment1).commit();
getSupportFragmentManager().beginTransaction().hide(fragment2).commit();
getSupportFragmentManager().beginTransaction().hide(fragment3).commit();
getSupportFragmentManager().beginTransaction().show(fragment4).commit();
getSupportFragmentManager().beginTransaction().hide(fragment5).commit();
}
public void b5(View view) {
b1.setTextColor(Color.BLACK);
b2.setTextColor(Color.BLACK);
b3.setTextColor(Color.BLACK);
b4.setTextColor(Color.BLACK);
b5.setTextColor(Color.RED);
getSupportFragmentManager().beginTransaction().hide(fragment1).commit();
getSupportFragmentManager().beginTransaction().hide(fragment2).commit();
getSupportFragmentManager().beginTransaction().hide(fragment3).commit();
getSupportFragmentManager().beginTransaction().hide(fragment4).commit();
getSupportFragmentManager().beginTransaction().show(fragment5).commit();
}
}
//f1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
>
<android.support.design.widget.TabLayout
android:id="@+id/tl"
android:layout_width="match_parent"
android:layout_height="100dp"
></android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="match_parent"
></android.support.v4.view.ViewPager>
</LinearLayout>
//ActivityFragment1
//内嵌的fragment
private View view;
private TabLayout tl;
private ViewPager vp;
private List<String> list = new ArrayList<>();
private List<Fragment> flist= new ArrayList<>();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view= inflater.inflate(R.layout.f1, container, false);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
tl = (TabLayout) view.findViewById(R.id.tl);
vp = (ViewPager) view.findViewById(R.id.vp);
//集合添加数据
list.add("动态");
list.add("热门");
list.add("发现");
//fragment集合
flist.add(new Fragment_dt());
flist.add(new Fragment_rm());
flist.add(new Fragment_fx());
//适配器
vp.setAdapter(new MAdapter(getActivity().getSupportFragmentManager()));
tl.setupWithViewPager(vp);
}
class MAdapter extends FragmentPagerAdapter {
public MAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return flist.get(position);
}
@Override
public int getCount() {
return flist.size();
}
@Override
public CharSequence getPageTitle(int position) {
return list.get(position);
}
}
}
//f2xml
handler图片轮播+xlistview上拉刷新加载
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/iw"
android:layout_width="match_parent"
android:layout_height="200dp" />
<com.example.dfx.view.XListView
android:layout_below="@id/iw"
android:id="@+id/lvs"
android:layout_width="match_parent"
android:layout_height="match_parent"></com.example.dfx.view.XListView>
</RelativeLayout>
//Fragment2
private List<Beans.DataBean> list=new ArrayList<>();
private ImageView iw;
private ArrayList<String> strings;
private View view;
private int index=0;
private XListView lvs;
private Mydapter mydapter;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view= inflater.inflate(R.layout.f2, container, false);
return view;
}
Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
if (index==strings.size()){
index=0;
}
ImageLoader.getInstance().displayImage(strings.get(index),iw);
index++;
sendEmptyMessageDelayed(1,500);
}
};
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
intview();
pathss();
strings = new ArrayList<String>();
strings.add("http://i02.pictn.sogoucdn.com/4f1a032a46d14846");
strings.add("http://i02.pictn.sogoucdn.com/3816828c8bb97482");
strings.add("http://i04.pictn.sogoucdn.com/d833eefe2b09cccb");
strings.add("http://i01.pictn.sogoucdn.com/69ea8a40fc1f3e0f");
strings.add("http://i02.pictn.sogoucdn.com/a23b5e73f418e05b");
handler.sendEmptyMessageDelayed(1,2000);
}
private void pathss() {
Myyask myyask = new Myyask();
myyask.execute("http://www.yulin520.com/a2a/impressApi/news/mergeList?pageSize=10&page=1");
}
private void intview() {
iw = (ImageView) view.findViewById(R.id.iw);
lvs = (XListView) view.findViewById(R.id.lvs);
lvs.setPullLoadEnable(true);
lvs.setXListViewListener(this);
mydapter = new Mydapter();
lvs.setAdapter(mydapter);
}
public void onLoad(){
lvs.stopRefresh();
lvs.stopLoadMore();
lvs.setRefreshTime("刚刚");
}
@Override
public void onRefresh() {
list.clear();
new Myyask().execute("http://www.yulin520.com/a2a/impressApi/news/mergeList?pageSize=10&page=1");
onLoad();
}
@Override
public void onLoadMore() {
new Myyask().execute("http://www.yulin520.com/a2a/impressApi/news/mergeList?pageSize=10&page=1");
onLoad();
}
class Myyask extends AsyncTask<String,Void,String>{
@Override
protected String doInBackground(String... strings) {
try {
URL url = new URL(strings[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
int code = connection.getResponseCode();
if (code==200){
InputStream inputStream = connection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuffer buffer = new StringBuffer();
String string="";
while ((string=bufferedReader.readLine())!=null){
buffer.append(string);
}
return buffer.toString();
}
} catch (IOException e) {
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Gson gson = new Gson();
Beans beans = gson.fromJson(s, Beans.class);
List<Beans.DataBean> data = beans.getData();
list.addAll(data);
mydapter.notifyDataSetChanged();
}
}
class Mydapter extends BaseAdapter{
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHoder vh;
if (view==null){
vh=new ViewHoder();
view = view.inflate(getActivity(), R.layout.item, null);
vh.tvs=(TextView) view.findViewById(R.id.tvs);
vh.ivss=(ImageView) view.findViewById(R.id.ivss);
view.setTag(vh);
}else {
vh = (ViewHoder) view.getTag();
}
vh.tvs.setText(list.get(i).getTitle());
ImageLoader.getInstance().displayImage(list.get(i).getImg(),vh.ivss);
return view;
}
}
class ViewHoder{
public TextView tvs;
public ImageView ivss;
}
}
//f3Griderview
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:id="@+id/ww"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2"
/>
</LinearLayout>
//fragment_fx
private View view;
private GridView gw;
private MyGride myGride;
private List<Beank.DataBean> list=new ArrayList<>();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.f3, container, false);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
gw = (GridView) view.findViewById(R.id.ww);
myGride = new MyGride();
gw.setAdapter(myGride);
pathsss();
}
private void pathsss() {
Mydask mydask = new Mydask();
mydask.execute("http://www.yulin520.com/a2a/impressApi/news/mergeList?pageSize=10&page=1");
}
class Mydask extends AsyncTask<String,Void,String>{
@Override
protected String doInBackground(String... strings) {
try {
URL url = new URL(strings[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
int code = connection.getResponseCode();
if (code==200){
InputStream inputStream = connection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuffer buffer = new StringBuffer();
String string="";
while ((string=bufferedReader.readLine())!=null){
buffer.append(string);
}
return buffer.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Gson gson = new Gson();
Beank beank = gson.fromJson(s, Beank.class);
List<Beank.DataBean> data = beank.getData();
list.addAll(data);
myGride.notifyDataSetChanged();
}
}
class MyGride extends BaseAdapter{
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHoder vh;
if (view==null){
vh=new ViewHoder();
view = view.inflate(getActivity(), R.layout.grad, null);
vh.tvs=(TextView) view.findViewById(R.id.tv2);
vh.ivss=(ImageView) view.findViewById(R.id.icon_group);
view.setTag(vh);
}else {
vh = (ViewHoder) view.getTag();
}
vh.tvs.setText(list.get(i).getTitle());
ImageLoader.getInstance().displayImage(list.get(i).getImg(),vh.ivss);
return view;
}
}
class ViewHoder{
public TextView tvs;
public ImageView ivss;
}
}
//grad
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/tv2"
android:layout_width="200dp"
android:layout_height="200dp" />
<ImageView
android:id="@+id/icon_group"
android:layout_width="200dp"
android:layout_height="200dp" />
</LinearLayout>
//item
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/tvv"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello World!"
android:id="@+id/tvs"/>
<ImageView
android:id="@+id/ivss"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
//fragment_dt
private View view;
private XListView xlv;
private DisplayImageOptions options;
private List<JsonBean.ResultsBean> list = new ArrayList<>();
private MAdapter mAdapter;
private int n=1;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.xlv, container, false);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
xlv = (XListView)view.findViewById(R.id.xlv);
this.xlv.setPullLoadEnable(true);
this.xlv.setXListViewListener(this);
//sd卡
options = new DisplayImageOptions.Builder()
.cacheOnDisk(true) //sd卡
.cacheInMemory(true)
.build();
mAdapter = new MAdapter();
this.xlv.setAdapter(mAdapter);
new MAsyncTask().execute("http://gank.io/api/data/Android/10/1");
}
public void onLoad(){
xlv.stopRefresh();
xlv.stopLoadMore();
xlv.setRefreshTime("刚刚");
}
@Override
public void onRefresh() {
list.clear();
new MAsyncTask().execute("http://gank.io/api/data/Android/10/1");
onLoad();
}
@Override
public void onLoadMore() {
n++;
new MAsyncTask().execute("http://gank.io/api/data/Android/10/"+n);
onLoad();
}
class MAsyncTask extends AsyncTask<String,Void,String> {
private StringBuilder builder;
@Override
protected String doInBackground(String... strings) {
try {
//获取url
URL url = new URL(strings[0]);
//请求网络
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
int code = urlConnection.getResponseCode();
//判断是否返回成功
if(code==200){
//获取网络信息
InputStream inputStream = urlConnection.getInputStream();
BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream));
builder = new StringBuilder();
String s = "";
//拼接
while((s=bf.readLine())!=null){
builder.append(s);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return builder.toString();
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Log.e("Conan",s+"+-+-+-+-+-+-+-+-ss");
Gson gson = new Gson();
JsonBean jsonBean = gson.fromJson(s, JsonBean.class);
List<JsonBean.ResultsBean> results = jsonBean.getResults();
list.addAll(results);
mAdapter.notifyDataSetChanged();
}
}
//适配器
class MAdapter extends BaseAdapter {
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
class ViewHolder1{
TextView desc;
}
class ViewHolder2{
TextView desc;
ImageView img;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
int type = getItemViewType(i);
switch(type){
case 0:
ViewHolder1 vh1;
if (view == null){
view = View.inflate(getActivity(),R.layout.item1_layout,null);
vh1 = new ViewHolder1();
vh1.desc =(TextView) view.findViewById(R.id.desc);
view.setTag(vh1);
}else{
vh1 = (ViewHolder1) view.getTag();
}
vh1.desc.setText(list.get(i).getDesc());
break;
case 1:
ViewHolder2 vh2;
if (view == null){
view = View.inflate(getActivity(),R.layout.item2_layout,null);
vh2 = new ViewHolder2();
vh2.desc =(TextView) view.findViewById(R.id.descs);
vh2.img = view.findViewById(R.id.imgs);
view.setTag(vh2);
}else{
vh2 = (ViewHolder2) view.getTag();
}
vh2.desc.setText(list.get(i).getDesc());
ImageLoader.getInstance().displayImage(list.get(i).getImages().get(0),vh2.img,options);
break;
}
return view;
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public int getItemViewType(int position) {
if (list.get(position).getImages()==null){
return 0;
}else{
return 1;
}
}
}
}
//item1_layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/desc"
android:layout_width="match_parent"
android:layout_height="50dp" />
</LinearLayout>
//item2_layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imgs"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@mipmap/ic_launcher"
/>
<TextView
android:id="@+id/descs"
android:layout_width="match_parent"
android:layout_height="50dp" />
</LinearLayout>
//xlv
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<com.example.dfx.view.XListView
android:id="@+id/xlv"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.example.dfx.view.XListView>
</LinearLayout>
//接受的rawlayout传过来的值
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v=View.inflate(getActivity(),R.layout.item,null);
TextView tvv= (TextView) v.findViewById(R.id.tvv);
String value=getArguments().getString("value");
tvv.setText(value);
return v;
}
//网络判断、
public static int getNetype(Context context) {
int netType = -1;
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
//无网络
if (networkInfo == null) {
return netType;
}
int nType = networkInfo.getType();
//手机网络
if (nType == ConnectivityManager.TYPE_MOBILE) {
netType = 2;
} else if (nType == ConnectivityManager.TYPE_WIFI) {//wifi网络
netType = 1;
}
//返回
return netType;
}
//imageloder
File file = getExternalCacheDir();
ImageLoaderConfiguration build = new ImageLoaderConfiguration.Builder(this).memoryCacheExtraOptions(200, 200)//配置内存缓存图片的尺寸
.memoryCacheSize(2 * 1024 * 1024)//配置内存缓存的大小
.threadPoolSize(3)//配置加载图片的线程数
.threadPriority(1000)//配置线程的优先级
.diskCache(new UnlimitedDiskCache(file))//UnlimitedDiskCache 限制这个图片的缓存路径
.diskCacheFileCount(50)//配置sdcard缓存文件的数量
.diskCacheFileNameGenerator(new Md5FileNameGenerator())//MD5这种方式生成缓存文件的名字
.diskCacheSize(50 * 1024 * 1024)//在sdcard缓存50MB .memoryCacheExtraOptions(200, 200)//配置内存缓存图片的尺寸
.memoryCacheSize(2 * 1024 * 1024)//配置内存缓存的大小
.threadPoolSize(3)//配置加载图片的线程数
.threadPriority(1000)//配置线程的优先级
.diskCache(new UnlimitedDiskCache(file))//UnlimitedDiskCache 限制这个图片的缓存路径
.diskCacheFileCount(50)//配置sdcard缓存文件的数量
.diskCacheFileNameGenerator(new Md5FileNameGenerator())//MD5这种方式生成缓存文件的名字
.diskCacheSize(50 * 1024 * 1024)//在sdcard缓存50MB
.build();
ImageLoader.getInstance().init(build);
}
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
TABLAYOUT加依赖