首先是主
导包:design
PullToRefreshLayout依赖包
compile 'com.jwenfeng.pulltorefresh:library:1.0.3'
tablayout 抽屉布局 (头条框)
compile 'com.android.support:design:25.3.1'
无限轮播的依赖包
compile 'com.bigkoo:convenientbanner:2.0.5'
侧拉的依赖包
compile 'com.android.support:design:24.2.1'
网络请求的轮播
compile 'com.bigkoo:convenientbanner:2.0.5'
网络请求权限
外部存储
添加图片要注册权限
android:name=".MyApplication"
MainActivity
package com.example.shengbanla;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private FrameLayout fl;
private TextView sy;
private TextView qy;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fl = (FrameLayout) findViewById(R.id.fl);
sy = (TextView) findViewById(R.id.sy);
qy = (TextView) findViewById(R.id.qy);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.fl,new Main3Activity());
transaction.commit();
sy.setTextColor(Color.RED);
qy.setTextColor(Color.BLACK);
sy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.fl,new Main3Activity());
transaction.commit();
sy.setTextColor(Color.RED);
qy.setTextColor(Color.BLACK);
}
});
qy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.fl,new Main2Activity());
transaction.commit();
sy.setTextColor(Color.BLACK);
qy.setTextColor(Color.RED);
}
});
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
主布局
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
MyAdapter:
package com.example.shengbanla;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.List;
/**
* Created by DELL on 2017/9/20.
*/
public class MyAdapter extends BaseAdapter{
Context context;
List
public MyAdapter(Context context, List
this.context = context;
this.list = list;
}
final int tz=0;
final int tx=1;
@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) {
Asd asd = null;
Asdd asdd = null;
int type = getItemViewType(i);
if(view==null){
switch (type){
case tz:
asd = new Asd();
view = View.inflate(context, R.layout.item, null);
asd.img = (ImageView) view.findViewById(R.id.img);
asd.tv1 = (TextView) view.findViewById(R.id.tv1);
asd.tv2 = (TextView) view.findViewById(R.id.tv2);
view.setTag(asd);
break;
case tx:
asdd = new Asdd();
view = View.inflate(context, R.layout.item2, null);
asdd.img1 = (ImageView) view.findViewById(R.id.img1);
asdd.img2 = (ImageView) view.findViewById(R.id.img2);
asdd.img3 = (ImageView) view.findViewById(R.id.img3);
view.setTag(asdd);
break;
}
}switch (type) {
case tz:
asd = (Asd) view.getTag();
ImageLoader.getInstance().displayImage(list.get(i).getPicUrl(), asd.img);
asd.tv1.setText(list.get(i).getTitle());
asd.tv2.setText(list.get(i).getCtime());
break;
case tx:
asdd = (Asdd) view.getTag();
ImageLoader.getInstance().displayImage(list.get(i).getPicUrl(), asdd.img1);
ImageLoader.getInstance().displayImage(list.get(i).getPicUrl(), asdd.img2);
ImageLoader.getInstance().displayImage(list.get(i).getPicUrl(), asdd.img3);
break;
default:
break;
}
return view;
}
@Override
public int getItemViewType(int position) {
int p = position % 2;
if(p==0){
return tz;
}else{
return tx;
}
}
@Override
public int getViewTypeCount() {
return 2;
}
class Asdd{
public ImageView img1;
public ImageView img2;
public ImageView img3;
}
class Asd{
public ImageView img;
public TextView tv1;
public TextView tv2;
}
}
MyApplication:
package com.example.shengbanla;
import android.app.Application;
import android.content.Context;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import java.io.File;
/**
* Created by DELL on 2017/9/20.
*/
public class MyApplication extends Application{
@Override
public void onCreate() {
super.onCreate();
File files = new File("/sdcard/Rimg");
initImageLoader(getApplicationContext(),files);
}
public static void initImageLoader(Context context, File file) {
// This configuration tuning is custom. You can tune every option, you may tune some of them,
// or you can create default configuration by
// ImageLoaderConfiguration.createDefault(this);
// method.
ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
config.threadPriority(Thread.NORM_PRIORITY - 2);//线程池内加载的数量
config.denyCacheImageMultipleSizesInMemory();
config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
config.tasksProcessingOrder(QueueProcessingType.LIFO);
// config.diskCache(true);
config.writeDebugLogs(); // Remove for release app
config .diskCache(new UnlimitedDiskCache(file));//UnlimitedDiskCache 限制这个图片的缓存路径
config .diskCacheFileCount(50);//配置sdcard缓存文件的数量
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config.build());
}
}
Bean:
package com.example.shengbanla;
import java.util.List;
/**
* Created by DELL on 2017/9/20.
*/
public class Bean {
/**
* code : 200
* msg : success
* newslist : [{"ctime":"2017-09-20","title":"19岁少女被3男灌醉后....","description":"女人香V","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46813456.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=378×tamp=1505894420&signature=R5Upv*nVUWk7tcV-8ACdDGEMtrQ8aAf6oWrbTN40n6v9*ADsJCpv8Ry*BIQq8P7IGBBRxzttELrxmElWQ7zrvfccB3cV8xEHnztiEO8*ojk="},{"ctime":"2017-09-20","title":"当你觉得累时,请用心看看这段文字","description":"散文微小说","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-36341931.static/640","url":"https://mp.weixin.qq.com/s?src=16&ver=378×tamp=1505894420&signature=SaHwyBKUsTBLxevPcltEVNMfZX4o43ZFTK-RpcM-bcF8yNM1-z3AOgImTK3au0qII2wn3zaRAFSzNmCAe4HBfLH7hvnfbZYy*f-TTR8FCNg="},{"ctime":"2017-09-20","title":"女人与女人最大的区别,不是相貌,而是味道 !","description":"散文微小说","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-36341931.static/640","url":"https://mp.weixin.qq.com/s?src=16&ver=378×tamp=1505894419&signature=0p*OzTZ4-h0QHHOEaPm7oAjZO*XG84PR9K90ZTs872FeLTJn0CySphMzLn6qWGx8lbq8JiKzZw9NJg5BcTzOg8qZnm9iBv9JXOTFyUyUn7o="},{"ctime":"2017-09-20","title":"《使女的故事》太可怕,因为人类罪恶无需想象","description":"大家","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46814933.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=378×tamp=1505894419&signature=ZqmIj0jBADCNOVh4ZPRUAiBmTMl6BsDbdRpAKCkln*fX03J8CXPRFD0dZQb7kkRg-W-oTn*HPkM1DhLG-3w6zzHtSfES0fSwW-kD6tE2xBw="},{"ctime":"2017-09-20","title":"古典主义时期音乐","description":"尚音爱乐","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46813641.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=378×tamp=1505894419&signature=ewbuXnVIp2cyqWZpvgHoj1bqS*AsN1FNNSKyYnn6HhRODycUTtq-t2-3IAzq5KY7Uo-*FiW9B4mw4sWf0N2Vo*TwNQ8UXBo*H14gcU4VTJk="},{"ctime":"2017-09-20","title":"【20170919 李杜英文札记】可作新款iphone广告的小诗","description":"李杜的双语世界","picUrl":"https://t1.qpic.cn/mblogpic/f01a972dbcc1060fd456/2000","url":"https://mp.weixin.qq.com/s?src=16&ver=378×tamp=1505894418&signature=rei4BxiOECum5gIjtJGRlNYW0Gc0*FRzik7s2umIcw1Gc7fC84kjtBZ0SWTK3f57gNUyMuW4h*ZO6eZ4bal4iFAZChYSSBqKMnoOxM3fOh0="},{"ctime":"2017-09-20","title":"不幸的孩子往往来自这7种家庭,你家是吗?","description":"育儿团","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46589573.static/640","url":"https://mp.weixin.qq.com/s?src=16&ver=378×tamp=1505890820&signature=AYcjktcbvCB3c6hh47CJZyuTcBqWI*yM6E7j6p5bVPSeTSBnGey-5s4qvuNg6HROtmEACvK4FMA5O5wN4PBewj8-nyue4srHhBDu2bRsUvU="},{"ctime":"2017-09-20","title":"失踪的两名潜水员遗体找到了,他们到底是怎么死的?","description":"澎湃新闻","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46805558.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=378×tamp=1505890820&signature=I2dtLAtKXu6gI1lgYfobv76FQYrpZCos*L4LLZIjkdf0PnWR1sDnaHcKNdmWKL3GzTiHViXsWsufNDPffRtL7-YXGRcPa1ObaJW6VU7qCKM="},{"ctime":"2017-09-20","title":"注意了!欠款的,你不再是大爷了,50元就干掉你!","description":"泛家居圈","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46810470.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=378×tamp=1505890820&signature=Jndy6Hml2JgC3Fw-hflmvegnCuOce7xxlycZEwd1uOHpV2qdIWv*W5zVuO0WucXW7LxdSsfP7WrNAOenvmYXwbJmhpLac1le0-kEfMiGVR4="},{"ctime":"2017-09-20","title":"观石网拍指南","description":"观石录","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46811197.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=378×tamp=1505890819&signature=6CSkRhRoaqMOGhwXWk0xZvipcsxPPUz-Cp2H*C0dbRSVA0DPAPnj1R5*qq4z9-Sw50ny*heV87U*4oFX3T6GSnZHXZgX0XwvUpxK0GSVyR4="}]
*/
private int code;
private String msg;
private List
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public List
return newslist;
}
public void setNewslist(List
this.newslist = newslist;
}
public static class NewslistBean {
/**
* ctime : 2017-09-20
* title : 19岁少女被3男灌醉后....
* description : 女人香V
* picUrl : https://zxpic.gtimg.com/infonew/0/wechat_pics_-46813456.jpg/640
* url : https://mp.weixin.qq.com/s?src=16&ver=378×tamp=1505894420&signature=R5Upv*nVUWk7tcV-8ACdDGEMtrQ8aAf6oWrbTN40n6v9*ADsJCpv8Ry*BIQq8P7IGBBRxzttELrxmElWQ7zrvfccB3cV8xEHnztiEO8*ojk=
*/
private String ctime;
private String title;
private String description;
private String picUrl;
private String url;
public String getCtime() {
return ctime;
}
public void setCtime(String ctime) {
this.ctime = ctime;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPicUrl() {
return picUrl;
}
public void setPicUrl(String picUrl) {
this.picUrl = picUrl;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
}
NewsFragment:
package com.example.shengbanla;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
/**
* Created by DELL on 2017/9/20.
*/
public class NewsFragment extends Fragment{
private String pagesize="20";
private int page=1;
private String mstrings;
private PullToRefreshListView listView;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.news_layout, container, false);
listView = (PullToRefreshListView) view.findViewById(R.id.list_view);
listView.getRefreshableView();
listView.setMode(PullToRefreshBase.Mode.BOTH);
listView.setScrollingWhileRefreshingEnabled(true);
listView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2
// //完成下拉刷新操作
@Override
public void onPullDownToRefresh(PullToRefreshBase
refreshView.postDelayed(new Runnable() {
@Override
public void run() {
page=1;
getDataFromNet(mstrings,pagesize,page);
listView.onRefreshComplete();
}
}, 2000);
}
//完成上拉刷新操作
@Override
public void onPullUpToRefresh(PullToRefreshBase
page++;
refreshView.postDelayed(new Runnable() {
@Override
public void run() {
if(mstrings!=null&&pagesize!=null){
getDataFromNet(mstrings,pagesize,page);
}
listView.onRefreshComplete();
}
}, 2000);
}
});
/* //获取带有刷新的对应控件
2 pullToRefreshListView.getRefreshableView();
3 *//**
4 * 设置刷新的模式:常用的有三种
5 * PullToRefreshBase.Mode.BOTH //上下拉刷新都可以
6 * PullToRefreshBase.Mode.PULL_FROM_START //只允许下拉刷新
7 * PullToRefreshBase.Mode.PULL_FROM_END //只允许上拉刷新
8 *
9 *//*
10 pullToRefreshListView.setMode(PullToRefreshBase.Mode.PULL_FROM_END);
11 //设置是否允许刷新的时候可以滑动
12 pullToRefreshListView.setScrollingWhileRefreshingEnabled(true);*/
// PullToRefreshBase.Mode.BOTH //上下拉刷新都可以
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Bundle bundle = getArguments();
mstrings = bundle.getString("name","social");
getDataFromNet(mstrings,pagesize,page);
}
private void getDataFromNet(final String string, final String pagesize, final int page) {
AsyncTask
@Override
protected String doInBackground(Void... voids) {
// http://api.tianapi.com/wxnew/?key=71e58b5b2f930eaf1f937407acde08fe&num=10&page=8
String path = "http://api.tianapi.com/"+string+"/?key=71e58b5b2f930eaf1f937407acde08fe&num="+pagesize+"&page="+page+"";
try {
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
if ((connection.getResponseCode() == 200)) {
InputStream inputStream = connection.getInputStream();
String json = streamToString(inputStream,"utf-8");
return json;
}
} catch (java.io.IOException e) {
e.printStackTrace();
}
return "";
}
@Override
protected void onPostExecute(String json) {
Gson gson = new Gson();
Bean bean = gson.fromJson(json, Bean.class);
List
if (list != null) {
MyAdapter myAdapter = new MyAdapter(getActivity(), list);
listView.setAdapter(myAdapter);
}
}
};
asyncTask.execute();
}
private String streamToString(InputStream inputStream,String charset) {
try {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream,charset);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String s = null;
StringBuilder builder = new StringBuilder();
while ((s = bufferedReader.readLine()) != null){
builder.append(s);
}
bufferedReader.close();
return builder.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Main3Activity:
package com.example.shengbanla;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import java.util.ArrayList;
import java.util.List;
public class Main3Activity extends Fragment implements AdapterView.OnItemClickListener{
private TabLayout tabLayout;
private ViewPager viewPager;
private List
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_main3,null);
tabLayout = (TabLayout)view.findViewById(R.id.tablayout);
viewPager = (ViewPager) view.findViewById(R.id.vp);
list.add("社会新闻");
list.add("国内新闻");
list.add("国际新闻");
list.add("娱乐新闻");
list.add("国内体育行业");
list.add("NBA动态");
list.add("国足资讯");
viewPager.setAdapter(new FragmentPagerAdapter(getActivity().getSupportFragmentManager()) {
@Override
public CharSequence getPageTitle(int position) {
return list.get(position);
}
@Override
public Fragment getItem(int position) {
NewsFragment newsFragments = new NewsFragment();
Bundle bundle = new Bundle();
if(list.get(position).equals("社会新闻")){
bundle.putString("name","social");
}else if (list.get(position).equals("国内新闻")){
bundle.putString("name","guonei");
}else if (list.get(position).equals("国际新闻")){
bundle.putString("name","world");
}else if (list.get(position).equals("娱乐新闻")){
bundle.putString("name","huabian");
}else if (list.get(position).equals("国内体育行业")){
bundle.putString("name","tiyu");
}else if (list.get(position).equals("NBA动态")){
bundle.putString("name","nba");
}else if (list.get(position).equals("国足资讯")){
bundle.putString("name","football");
}
newsFragments.setArguments(bundle);
return newsFragments;
}
@Override
public int getCount() {
return list.size();
}
});
tabLayout.setupWithViewPager(viewPager);
return view;
}
@Override
public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
}
}
Main2Activity:
package com.example.shengbanla;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import com.youth.banner.Banner;
import java.util.ArrayList;
import java.util.List;
/**
* Created by DELL on 2017/9/21.
*/
public class Main2Activity extends Fragment implements AdapterView.OnItemClickListener{
private Banner banner;
private List
private static final String BANNER[] = new String[]{
"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46953548.jpg/640",
"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46953581.jpg/640",
"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46953591.jpg/640",
"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46953695.jpg/640",
"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46952789.jpg/640",
"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46952809.jpg/640",
"https://zxpic.gtimg.com/infonew/0/wechat_pics_-28221234.jpg/640",
"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46785289.jpg/640",
"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46941264.jpg/640",
};
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_main2,null);
banner = (Banner) view.findViewById(R.id.banner);
list = new ArrayList<>();
for(int i = 0;i
}
//设置加载样式
banner.setIndicatorGravity(Banner.CENTER);
banner.setBannerStyle(Banner.CIRCLE_INDICATOR_TITLE);
//是否自动轮播
banner.isAutoPlay(true);
//设置轮播的时间间隔
banner.setDelayTime(2000);
//设置加载的图片,解析出来的url
banner.setImages(list);
return view;
}
@Override
public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
}
}
下面是布局:
news_layout.xml
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
>
nav_header_main.xml:
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
app:srcCompat="@android:drawable/sym_def_app_icon" />
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="陈锐"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="看我的升班大计" />
item2:
android:layout_height="match_parent">
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
android:layout_height="match_parent">
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
item:
android:layout_height="match_parent">
android:layout_width="100dp"
android:layout_height="100dp" />
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/tv1">
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
content_main:
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.shengbanla.MainActivity"
tools:showIn="@layout/app_bar_main">
android:layout_height="match_parent"
>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
android:layout_height="match_parent"
android:layout_above="@+id/ll"
android:id="@+id/fl">
app_bar_main.xml:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.shengbanla.MainActivity">
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
activity_main3.xml:
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.shengbanla.Main3Activity">
android:layout_width="match_parent"
android:layout_height="40dp"
app:tabGravity="center"
app:tabIndicatorColor="#ff0000"
app:tabMode="scrollable"
app:tabSelectedTextColor="#ff0000"
app:tabTextColor="#00ff00">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tablayout">
activity_main2.xml:
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.shengbanla.Main2Activity">
android:layout_width="200dp"
android:layout_height="100dp">