側拉 橫向滑動tablayout 無限輪播
首先是主
導包: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'
網路請求許可權
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
外部儲存
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
新增圖片要註冊許可權
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;
}
}
主佈局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
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" />
</android.support.v4.widget.DrawerLayout>
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<Bean.NewslistBean> list;
public MyAdapter(Context context, List<Bean.NewslistBean> 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.
*/
private int code;
private String msg;
private List<NewslistBean> newslist;
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<NewslistBean> getNewslist() {
return newslist;
}
public void setNewslist(List<NewslistBean> newslist) {
this.newslist = newslist;
}
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<ListView>() {
// //完成下拉重新整理操作
@Override
public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
refreshView.postDelayed(new Runnable() {
@Override
public void run() {
page=1;
getDataFromNet(mstrings,pagesize,page);
listView.onRefreshComplete();
}
}, 2000);
}
//完成上拉重新整理操作
@Override
public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
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<Void, Void, String> asyncTask = new AsyncTask<Void, Void, String>() {
@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<Bean.NewslistBean> list = bean.getNewslist();
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<String> list = new ArrayList<String>();
@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{
@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.length;i++){
list.add(BANNER[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
<?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">
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
></com.handmark.pulltorefresh.library.PullToRefreshListView>
</LinearLayout>
nav_header_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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">
<ImageView
android:id="@+id/imageView"
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" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="陳銳"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="看我的升班大計" />
</LinearLayout>
item2:
<?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">
<ImageView
android:id="@+id/img1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
<ImageView
android:id="@+id/img2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
<ImageView
android:id="@+id/img3"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
</LinearLayout>
<?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">
<ImageView
android:id="@+id/img1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
<ImageView
android:id="@+id/img2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
<ImageView
android:id="@+id/img3"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
</LinearLayout>
item:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/img"
android:layout_width="100dp"
android:layout_height="100dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/tv1">
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv2"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
content_main:
<?xml version="1.0" encoding="utf-8"?>
<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: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">
<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:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:id="@+id/sy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="首頁" />
<Button
android:id="@+id/qy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="詳情頁" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/ll"
android:id="@+id/fl"></FrameLayout>
</RelativeLayout>
</RelativeLayout>
app_bar_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context="com.example.shengbanla.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
activity_main3.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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.support.design.widget.TabLayout
android:id="@+id/tablayout"
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.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tablayout"></android.support.v4.view.ViewPager>
</RelativeLayout>
activity_main2.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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">
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="200dp"
android:layout_height="100dp"></com.youth.banner.Banner>
</RelativeLayout>