全功能技能,有錯誤待改進
一、build.gradle加依賴app/build.gradle:32
compile project(':imageloaderlibrary')
compile 'com.google.code.gson:gson:2.2.4'
compile project(':pullToRefreshlibrary')
compile 'com.github.andyoom:draggrid:v1.0.1'
二、AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name="com.bwie.main.lianxi_01.app.imageloader"
三、建立基類Baseactivity與Basefragment
Baseactivity
//基類Activity public abstract class BaseActivity extends AppCompatActivity{ @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); //建立一個方法 init(); } //初始化 private void init() { setFullScreen(); setContentView(initLayout()); findView(); setOnClickLisener(); initData(); } //設定點選事件 protected abstract void setOnClickLisener(); //初始化資料 protected abstract void initData(); //查詢控制元件 protected abstract void findView(); //設定全屏 protected abstract void setFullScreen(); //填充佈局 protected abstract int initLayout(); //全屏 protected void fullScreen() { // 設定全屏 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } }
Basefragment
//基類Fragment public abstract class BaseFragment extends Fragment{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //Inflate the layout for this fragment return initLayout(inflater, container); } //填充佈局 protected abstract View initLayout(LayoutInflater inflater, ViewGroup container);
4、activity_main
activity_main.xml 5秒跳轉到 activity_show.xml ,實現漸變效果
public class MainActivity extends BaseActivity implements Animation.AnimationListener{
//漸變動畫
private AlphaAnimation alphaAnimation;
//根佈局
private RelativeLayout rlSplash;
@Override
protected void setOnClickLisener() {
}
@Override
protected void initData() {
//設定漸變時間
alphaAnimation = new AlphaAnimation(0, 1);
//設定跳轉時間
alphaAnimation.setDuration(2000);
//設定跳轉方法
alphaAnimation.setAnimationListener(this);
//開始漸變
rlSplash.startAnimation(alphaAnimation);
}
@Override
protected void findView() {
//初始化控制元件
rlSplash = (RelativeLayout) findViewById(R.id.rl_splash);
}
@Override
protected void setFullScreen() {
fullScreen();
}
@Override
protected int initLayout() {
return R.layout.activity_main;
}
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
//跳轉
Intent intent = new Intent(MainActivity.this,ShowActivity.class);
startActivity(intent);
finish();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
}
五、ShowActivity
package com.bwie.main.lianxi_01.activity;
import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioGroup;
import com.bwie.main.lianxi_01.R;
import com.bwie.main.lianxi_01.adapter.MyFragmentAdapter;
import com.bwie.main.lianxi_01.fragment.Fragment1;
import com.bwie.main.lianxi_01.fragment.Fragment2;
import com.bwie.main.lianxi_01.fragment.Fragment3;
import com.bwie.main.lianxi_01.fragment.Fragment4;
import java.util.ArrayList;
import java.util.List;
//主頁
public class ShowActivity extends BaseActivity {
private DrawerLayout dra_layout;
private ImageView img_shou;
private ImageView img_shous;
private ViewPager view_pager;
private RadioGroup radio_group;
private List<Fragment> list;
private MyFragmentAdapter adapterf;
//事件
@Override
protected void setOnClickLisener() {
//點選主頁的頭像,開啟側邊欄
img_shou.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dra_layout.openDrawer(Gravity.LEFT);
}
});
//點選側邊欄的頭像,關閉側邊欄
img_shous.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dra_layout.closeDrawer(Gravity.LEFT);
}
});
//建立四個fragment,放入一個Fragment的集合裡面
Fragment1 fragment1 = new Fragment1();
Fragment2 fragment2 = new Fragment2();
Fragment3 fragment3 = new Fragment3();
Fragment4 fragment4 = new Fragment4();
list = new ArrayList<>();
list.add(fragment1);
list.add(fragment2);
list.add(fragment3);
list.add(fragment4);
//建立介面卡+設定介面卡
adapterf = new MyFragmentAdapter(getSupportFragmentManager(),list);
view_pager.setAdapter(adapterf);
//滑動viewpager,按鈕跟著改變。
view_pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
radio_group.check(radio_group.getChildAt(position).getId());
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
//點選按鈕,viewpager跟著改變。
radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
switch (checkedId){
case R.id.dd1:
view_pager.setCurrentItem(0);
break;
case R.id.dd2:
view_pager.setCurrentItem(1);
break;
case R.id.dd3:
view_pager.setCurrentItem(2);
break;
case R.id.dd4:
view_pager.setCurrentItem(3);
break;
}
}
});
}
@Override
protected void initData() {
// 選中第一個頁面
}
@Override
protected void findView() {
//初始化控制元件
dra_layout = (DrawerLayout) findViewById(R.id.dra_layout);
img_shou = (ImageView) findViewById(R.id.img_shou);
img_shous = (ImageView) findViewById(R.id.img_shous);
view_pager = (ViewPager) findViewById(R.id.view_pager);
radio_group = (RadioGroup) findViewById(R.id.radio_group);
}
@Override
protected void setFullScreen() {
}
//指定頁面
@Override
protected int initLayout() {
return R.layout.activity_show;
}
}
6、三個adapter
fragment 的介面卡MyFragmentAdapter
package com.bwie.main.lianxi_01.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.List;
/**
* Created by admin on 2018/7/25.
*/
public class MyFragmentAdapter extends FragmentPagerAdapter{
private List<Fragment> list;
public MyFragmentAdapter(FragmentManager fm, List<Fragment> list) {
super(fm);
this.list = list;
}
@Override
public Fragment getItem(int position) {
return list.get(position);
}
@Override
public int getCount() {
return list.size();
}
}
輪播的介面卡MyImgAdapter
package com.bwie.main.lianxi_01.adapter;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.util.List;
/**
* Created by admin on 2018/7/26.
*/
public class MyImgAdapter extends PagerAdapter{
private Context context;
private List<ImageView> list;
public MyImgAdapter(Context context, List<ImageView> list) {
this.context = context;
this.list = list;
}
@Override
public int getCount() {
return Integer.MAX_VALUE;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = list.get(position%list.size());
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
container.addView(imageView);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
資料庫的介面卡MyPullAdapter
package com.bwie.main.lianxi_01.adapter;
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.bwei.imageloaderlibrary.utils.ImageLoaderUtils;
import com.bwie.main.lianxi_01.R;
import com.bwie.main.lianxi_01.bean.Pulllist;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.List;
/**
* Created by admin on 2018/7/26.
*/
public class MyPullAdapter extends BaseAdapter{
private Context context;
private List<Pulllist.DataBean> list;
public MyPullAdapter(Context context, List<Pulllist.DataBean> list) {
this.context = context;
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null){
convertView = View.inflate(context, R.layout.include1,null);
holder = new ViewHolder();
holder.img_include = convertView.findViewById(R.id.img_include);
holder.title_include = convertView.findViewById(R.id.title_include);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
//圖片快取路徑
DisplayImageOptions options = ImageLoaderUtils.getOptions();
ImageLoader.getInstance().displayImage(list.get(position).getThumbnail_pic_s(),holder.img_include,options);
holder.title_include.setText(list.get(position).getTitle());
return convertView;
}
public class ViewHolder{
ImageView img_include;
TextView title_include;
}
}
7、imageloader
package com.bwie.main.lianxi_01.app;
import android.app.Application;
import com.bwei.imageloaderlibrary.utils.ImageLoaderUtils;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
/**
* Created by admin on 2018/7/25.
*/
public class imageloader extends Application{
@Override
public void onCreate() {
super.onCreate();
//關聯
ImageLoaderConfiguration configuration = ImageLoaderUtils.getConfiguration(this);
ImageLoader.getInstance().init(configuration);
}
}
8、HttpUtils
package com.bwie.main.lianxi_01.utils;
import android.os.AsyncTask;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* Created by admin on 2018/7/25.
*/
public class HttpUtils {
private getdatajsonlisten getdatajsonlisten;
private static HttpUtils httpUtils;
public static HttpUtils getinstance(){
if(httpUtils==null){
httpUtils =new HttpUtils();
}
return httpUtils;
}
public void getdata(String url){
Myasync myasync = new Myasync();
myasync.execute(url);
}
public class Myasync extends AsyncTask<String,Integer,String> {
@Override
protected String doInBackground(String... params) {
try {
String path =params[0];
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
connection.setRequestMethod("GET");
if(connection.getResponseCode()==200){
InputStream inputStream = connection.getInputStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] bytes = new byte[1024];
int len =0;
while ((len=inputStream.read(bytes))!=-1){
bos.write(bytes,0,len);
}
inputStream.close();
bos.close();
String json = bos.toString();
return json;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
getdatajsonlisten.datajson1(s);
}
}
public interface getdatajsonlisten{
public void datajson1(String json);
}
public void setdatajsonlisten(getdatajsonlisten getdatajsonlisten){
this.getdatajsonlisten =getdatajsonlisten;
}
}
9、viewpager
package com.bwie.main.lianxi_01.vipager;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
/**
* Created by admin on 2018/7/25.
*/
public class viewpager extends ViewPager{
public viewpager(Context context) {
super(context);
}
public viewpager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected boolean dispatchGenericFocusedEvent(MotionEvent event) {
return super.dispatchGenericFocusedEvent(event);
}
}
10、三個bean包
資料庫的
package com.bwie.main.lianxi_01.bean;
/**
* Created by admin on 2018/7/28.
*/
public class Dbbean {
private int id;
private String url;
private String json;
public Dbbean() {
}
public Dbbean(String url, String json) {
this.url = url;
this.json = json;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getJson() {
return json;
}
public void setJson(String json) {
this.json = json;
}
@Override
public String toString() {
return "ShopBean{" +
"id=" + id +
", url='" + url + '\'' +
", json='" + json + '\'' +
'}';
}
}
pull和imgloader的
11、資料庫
Dbbean
package com.bwie.main.lianxi_01.bean;
/**
* Created by admin on 2018/7/28.
*/
public class Dbbean {
private int id;
private String url;
private String json;
public Dbbean() {
}
public Dbbean(String url, String json) {
this.url = url;
this.json = json;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getJson() {
return json;
}
public void setJson(String json) {
this.json = json;
}
@Override
public String toString() {
return "ShopBean{" +
"id=" + id +
", url='" + url + '\'' +
", json='" + json + '\'' +
'}';
}
}
Dao
package com.bwie.main.lianxi_01.db;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.bwie.main.lianxi_01.bean.Dbbean;
import java.util.ArrayList;
import java.util.List;
/**
* Created by admin on 2018/7/28.
*/
public class Dao {
private final SQLiteDatabase writableDatabase;
public Dao(Context context) {
MyHelper helper = new MyHelper(context);
writableDatabase = helper.getWritableDatabase();
}
public List<Dbbean> cha(String url) {
List<Dbbean> list = new ArrayList<>();
Cursor cursor = writableDatabase.rawQuery("select * from shop where url = ?", new String[]{url});
while(cursor.moveToNext()){
String url1 = cursor.getString(cursor.getColumnIndex("url"));
String json = cursor.getString(cursor.getColumnIndex("json"));
list.add(new Dbbean(url1,json));
}
return list;
}
public void add(String url,String json){
ContentValues values = new ContentValues();
values.put("url",url);
values.put("json",json);
writableDatabase.replace("shop",null,values);
}
}
MyHelper
package com.bwie.main.lianxi_01.db;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by admin on 2018/7/28.
*/
public class MyHelper extends SQLiteOpenHelper{
public MyHelper(Context context) {
super(context, "bwie.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table shop(_id integer primary key autoincrement,url TEXT,json TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
12、fragment的方法
Fragment1
package com.bwie.main.lianxi_01.fragment;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;
import com.andy.library.ChannelActivity;
import com.andy.library.ChannelBean;
import com.bwei.imageloaderlibrary.utils.ImageLoaderUtils;
import com.bwie.main.lianxi_01.R;
import com.bwie.main.lianxi_01.adapter.MyImgAdapter;
import com.bwie.main.lianxi_01.adapter.MyPullAdapter;
import com.bwie.main.lianxi_01.bean.Dbbean;
import com.bwie.main.lianxi_01.bean.Imglb;
import com.bwie.main.lianxi_01.bean.Pulllist;
import com.bwie.main.lianxi_01.db.ConUtils;
import com.bwie.main.lianxi_01.db.Dao;
import com.bwie.main.lianxi_01.utils.HttpUtils;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class Fragment1 extends BaseFragment {
private View view;
private ViewPager viewpager_lb;
private List<ImageView> imglist = new ArrayList<>();
private MyImgAdapter myImgAdapter;
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == 0){
String json = (String) msg.obj;
Gson gson = new Gson();
Imglb imglb = gson.fromJson(json, Imglb.class);
List<Imglb.DataBean> dataimg = imglb.getData();
for (int i = 0 ; i<dataimg.size() ; i++){
String s = dataimg.get(i).getImg();
ImageView imageView = new ImageView(getActivity());
DisplayImageOptions options = ImageLoaderUtils.getOptions();
ImageLoader.getInstance().displayImage(s,imageView,options);
imglist.add(imageView);
}
myImgAdapter = new MyImgAdapter(getActivity(),imglist);
viewpager_lb.setAdapter(myImgAdapter);
}else if (msg.what == 1){
int i = viewpager_lb.getCurrentItem();
i++;
viewpager_lb.setCurrentItem(i);
handler.sendEmptyMessageDelayed(1,2000);
}
}
};
private PullToRefreshListView pull_list;
private int page = 1;
private MyPullAdapter myPullAdapter;
private List<Pulllist.DataBean> listpull = new ArrayList<>();
private String paths = "http://www.xieast.com/api/news/news.php?page=";
private TabLayout tab_layout;
private List<String> list1;
private ImageView img_gl;
private String[] titles = {"推薦", "熱點", "上海", "視訊", "社會",
"訂閱", "娛樂", "圖片", "科技", "汽車",
"體育", "財經", "軍事", "國際", "段子",
"趣圖", "美女", "健康", "正能量", "特賣",
"中國好聲音", "歷史", "時尚", "闢謠", "探索", "美國",
"搞笑", "故事", "奇葩", "情感"};
private Dao dao;
private String url = paths + page;
//主方法
@Override
protected View initLayout(LayoutInflater inflater, ViewGroup container) {
view = inflater.inflate(R.layout.frg1,container,false);
//初始化控制元件
tab_layout = view.findViewById(R.id.tab_layout);
viewpager_lb = view.findViewById(R.id.viewpager_lb);
pull_list = view.findViewById(R.id.pull_list);
img_gl = view.findViewById(R.id.img_gl);
//呼叫方法
getfromtab();
getservicelb();
getfromnetpull();
return view;
}
//導航欄操作
private void getfromtab() {
//導航欄:建立一個String集合,放入名稱
list1 = new ArrayList<>();
list1.add("首頁");
list1.add("汽車");
list1.add("彩票");
list1.add("丁殼");
//設定模式
tab_layout.setTabMode(TabLayout.MODE_FIXED);
//新增標籤選項
tab_layout.addTab(tab_layout.newTab().setText(list1.get(0)));
tab_layout.addTab(tab_layout.newTab().setText(list1.get(1)));
tab_layout.addTab(tab_layout.newTab().setText(list1.get(2)));
tab_layout.addTab(tab_layout.newTab().setText(list1.get(3)));
img_gl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<ChannelBean> lists = new ArrayList<>();
for (int i = 0; i < 15; i++) {
//建立一個list需要的物件
ChannelBean bean = null;
if (i < 10) {
//前五個預設選中
bean = new ChannelBean(titles[i], true);
} else {
bean = new ChannelBean(titles[i], false);
}
lists.add(bean);
}
//跳轉並傳值
ChannelActivity.startChannelActivity((AppCompatActivity) getActivity(), lists);
}
});
}
//寫輪播操作
private void getservicelb() {
new Thread(){
@Override
public void run() {
super.run();
String pathh ="http://www.xieast.com/api/banner.php";
try {
URL url = new URL(pathh);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
connection.setRequestMethod("GET");
if (connection.getResponseCode() == 200){
InputStream inputStream = connection.getInputStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] bytes = new byte[1024];
int len = 0 ;
while ((len = inputStream.read(bytes))!=-1){
bos.write(bytes,0,len);
}
inputStream.close();
bos.close();
String json = bos.toString();
Message message = new Message();
message.what=0;
message.obj=json;
handler.sendMessage(message);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
//迴圈
@Override
public void onResume() {
super.onResume();
handler.sendEmptyMessageDelayed(1,2000);
}
//銷燬,onDestroy起衝突,所以要用onPause來銷燬
@Override
public void onDestroy() {
super.onDestroy();
handler.removeCallbacksAndMessages(null);
}
//銷燬
@Override
public void onPause() {
super.onPause();
handler.removeCallbacksAndMessages(null);
}
//寫主頁pullreferase
private void getfromnetpull() {
//支援重新整理和載入
pull_list.setMode(PullToRefreshBase.Mode.BOTH);
//建立監聽方法
pull_list.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
@Override
public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
//下拉
page =1;
getfromnet();
}
@Override
public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
//上拉
page +=1;
getfromnet();
}
});
//建立+設定pull的介面卡
myPullAdapter = new MyPullAdapter(getActivity(),listpull);
pull_list.setAdapter(myPullAdapter);
//建立Dao方法,呼叫Dao方法裡面的查詢,並判斷網路連線
dao = new Dao(getActivity());
List<Dbbean> cha = dao.cha(url);
if(cha!=null){
for (int i = 0; i <cha.size() ; i++) {
Pulllist pulllist = preajson(cha.get(i).getJson());
List<Pulllist.DataBean> data = pulllist.getData();
listpull.addAll(data);
}
}else{
if(ConUtils.iscon(getActivity())){
getfromnet();
}else{
Toast.makeText(getActivity(),"請開啟網路",Toast.LENGTH_SHORT).show();
}
}
}
//列表的解析
private Pulllist preajson(String json) {
Gson gson = new Gson();
return gson.fromJson(json,Pulllist.class);
}
//pull的資料操作
private void getfromnet() {
//解析
HttpUtils httpUtils = HttpUtils.getinstance();
httpUtils.getdata(url);
httpUtils.setdatajsonlisten(new HttpUtils.getdatajsonlisten() {
@Override
public void datajson1(String json) {
//儲存資料到資料庫
dao.add(url,json);
Gson gson = new Gson();
Pulllist pulllist = gson.fromJson(json, Pulllist.class);
List<Pulllist.DataBean> datapul = pulllist.getData();
if (page == 1){
listpull.clear();
}
listpull.addAll(datapul);
//重新整理介面卡.
myPullAdapter.notifyDataSetChanged();
//重新整理完成
pull_list.onRefreshComplete();
}
});
}
}
Fragment2,3,4
package com.bwie.main.lianxi_01.fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bwie.main.lianxi_01.R;
public class Fragment2 extends BaseFragment {
@Override
protected View initLayout(LayoutInflater inflater, ViewGroup container) {
View view = inflater.inflate(R.layout.frg2,container,false);
return view;
}
}
13、selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@color/colorAccent" />
<item android:state_checked="false" android:drawable="@color/colorPrimary" />
</selector>
14、activity_show.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/dra_layout"
tools:context="com.bwie.main.lianxi_01.activity.ShowActivity">
<!-- 側邊頁面-->
<LinearLayout
android:layout_width="300dp"
android:layout_height="match_parent"
android:background="#C0C0C0"
android:layout_gravity="start"
>
<ImageView
android:id="@+id/img_shous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_marginTop="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="側邊欄裡面"
android:textSize="25dp" />
</LinearLayout>
<!-- 主頁面-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#dd3">
<ImageView
android:id="@+id/img_shou"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_marginTop="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="首頁"
android:textSize="23dp" />
</RelativeLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8" />
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<RadioButton
android:id="@+id/dd1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:button="@null"
android:background="@drawable/selector"
android:text="丁殼"
android:textColor="#FFFF00"
android:textSize="28dp"
/>
<RadioButton
android:id="@+id/dd2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:button="@null"
android:background="@drawable/selector"
android:text="大頭"
android:textColor="#FFFF00"
android:textSize="28dp"
/>
<RadioButton
android:id="@+id/dd3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:background="@drawable/selector"
android:gravity="center"
android:text="奔扛"
android:textColor="#FFFF00"
android:textSize="28dp"
/>
<RadioButton
android:id="@+id/dd4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:background="@drawable/selector"
android:gravity="center"
android:text="保建"
android:textColor="#FFFF00"
android:textSize="28dp"
/>
</RadioGroup>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
15、frg1.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.bwie.main.lianxi_01.fragment.Fragment1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9"/>
<ImageView
android:id="@+id/img_gl"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/ic_add_box_black_24dp"/>
</LinearLayout>
<com.bwie.main.lianxi_01.vipager.viewpager
android:id="@+id/viewpager_lb"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4" />
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/pull_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6" />
</LinearLayout>
16、include1.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/img_include"
android:layout_width="120dp"
android:layout_height="80dp"
android:src="@drawable/ic_wb_auto_black_24dp"/>
<TextView
android:id="@+id/title_include"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title_include"
android:textSize="22dp"
android:layout_marginTop="12dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/img_include"
android:layout_toEndOf="@+id/img_include" />
</RelativeLayout>
17、四個fragment外掛,res下的drawable,手動新增,右擊new---vector Asset
相關推薦
全功能技能,有錯誤待改進
一、build.gradle加依賴app/build.gradle:32 compile project(':imageloaderlibrary') compile 'com.google.code.gson:gson:2.2.4' compile
elasticsearch5.0啟動出現的錯誤(自己做過測試,有錯誤可以在這上面找)
elasticsearch5.0啟動失敗,出現如下提示: 1、Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) fail
pythonQt4 實現活動倒計時小程式,有背景音樂圖片,全屏等小功能
利用python GUI工具QtDesigner 生成了初始介面,pythonQt4後期的編寫,做成了一個活動倒計時小程式。包括了pythonQt4編寫介面的大部分技巧,如介面的繪製,事件響應,事件過載等,在github上有對應的源程式,裡面寫有註釋。這個活動小程式具有如下功
APICloud首款全功能集成開發工具重磅發布,彰顯雲端一體理念
tro ebs 常用 訪問 效率 提交代碼 svn app制作 全部 近日,APICloud重磅推出首款雲端一體的全功能集成開發工具——APICloud Studio 2。為了更深入了解這款開發工具的特性及優勢,APICloud CTO 鄒達針對幾個核心問題做出了解答。
怎樣使用“高清IPTV”的EGP功能,有圖有真相哦
tor net http site upload 索引 nbsp 快速 方案 所謂 EPG就是 電子節目菜單。可是你是否知道 EPG 並非單純的“節目菜單”? IPTV 所提供的各種業務的索引及導航都是通過 EPG系統來完成的。 IPTV EPG 實際上就是IPTV的一
eclipse,代碼中有錯誤,項目中卻不顯示紅叉
tails pen ces style pos mpi btn project trac ***修改eclipse 代碼提示級別1.單個項目修改項目上右鍵-->properties-->java compiler-->building-->enabl
第三百六十八節,Python分布式爬蟲打造搜索引擎Scrapy精講—elasticsearch(搜索引擎)用Django實現搜索的自動補全功能
技術 django 分布 全功能 -s col ron 搜索 創建 第三百六十八節,Python分布式爬蟲打造搜索引擎Scrapy精講—用Django實現搜索的自動補全功能 elasticsearch(搜索引擎)提供了自動補全接口 官方說明:https://www
【easyui-combobox】下拉菜單自動補全功能,Ajax獲取遠程數據源
combo -c -o efi 字段 data app script resp 這個是針對easyUI的下拉菜單使用的,Ajax獲取遠程數據源 HTML 頁面 <input id="uname" name="uname" class="easyui-combo
文件操作,是一個存為字符串格式的登陸系統,有增刪改查的功能,但不是我想要的。。。
str repl 修改 blog 一個 ice body pwd 刪除 def register(NAME, PWD, TEL): with open(‘userdate.txt‘, ‘a‘, encoding=‘utf-8‘) as f: new
現有n堆球,其中n是偶數,第i堆中有 ai 個球。現需要將其中 n / 2 堆中的球數全變成完 全平方數,另外的 n / 2 全不為完全平方數。
bcd dba amp com http abc 一行 增加 完全平方數 【問題描述】現有n堆球,其中n是偶數,第i堆中有 ai 個球。現需要將其中 n / 2 堆中的球數全變成完全平方數,另外的 n / 2 全不為完全平方數。你每一次操作可以選擇任意一堆增加或拿走(前提不
判斷下列語句是否正確,如果有錯誤,請指出錯誤所在?interface A{
是否 ace shc 出錯 解答 nts face interface 返回 判斷下列語句是否正確,如果有錯誤,請指出錯誤所在? interface A{ int add(final A a); } class B implements A{ long
WeTest功能優化第3期:業內首創,有聲音的雲真機
第3期功能優化目錄 【雲真機遠端除錯】音訊同步傳輸實現測試有聲 【相容性測試報告】新增視訊助力動態定位問題 【雲真機遠端除錯】選單欄優化助力機型選擇 本期介紹的新功能,秉承創造使用者需求的理念,在雲真機聲音、報告截圖(視訊)、雲真機選單欄三大模板
CF E. Vasya and a Tree】 dfs+樹狀陣列(給你一棵n個節點的樹,每個點有一個權值,初始全為0,m次操作,每次三個數(v, d, x)表示只考慮以v為根的子樹,將所有與v點距離小於等於d的點權值全部加上x,求所有操作完畢後,所有節點的值)
題意: 給你一棵n個節點的樹,每個點有一個權值,初始全為0,m次操作,每次三個數(v, d, x)表示只考慮以v為根的子樹,將所有與v點距離小於等於d的點權值全部加上x,求所有操作完畢後,所有節點的值 首先要明確兩件事情性質1.每個人的操作只會影響到他的子孫(包括自己) 性質1.每個人的操
詳解centos7虛擬機器安裝elasticsearch5.0.x-安裝篇(自己做測試了,es啟動有錯誤可以在這上面找)
本篇文章主要介紹了centos7虛擬機器安裝elasticsearch5.0.x-安裝篇,具有一定的參考價值,感興趣的小夥伴們可以參考一下。 centos7虛擬機器安裝elasticsearch5.0.x-安裝篇 請預先安裝jdk詳細步驟請參考://www.jb51.net/softjc/1
forms元件(註冊使用者講解)(校驗欄位功能,渲染模板功能,渲染錯誤資訊功能,區域性鉤子渲染錯誤資訊,全域性鉤子渲染錯誤資訊)
forms元件 from django import forms class Myforms(forms.Form): name = forms.CharField(max_length=8,min_length=3 ,label='使用者名稱',
資料庫(二)tab補全功能,使資料庫支援簡體中文,日誌管理,備份指令碼
一、如何在MySQL資料庫中使用tab鍵補全功能 1.修改主配置檔案/etc/my.cnf vim /etc/my.cnf [mysql] #no-auto-rehash auto-rehash 2.重啟MySQL服務,登入測試 /etc/init.d/mysqld
一對一聊天系統核心功能實現方式有哪些,哪種方式可取?
一對一社交平臺我們可以在應用商店裡看到很多,他們都屬於一對一聊天系統的範疇,只是功能各異,各有各的產品定位及運營特色。然而它們有一個共同的核心功能:使用者間的一對一視訊(或語音)聊天。那麼各具特色的一對一聊天系統,它的核心功能是如何實現的呢? 常見的一對一聊天功能的實現方式有以下幾種: 1.
Kiwi TCMS 6.3 釋出,全功能測試用例管理系統
Kiwi TCMS 6.3 已釋出,Kiwi TCMS 是一個集測試計劃、測試執行和測試用例於一身的管理系統,用 Python 和 Django 編寫。它具有許多強大的功能,如 Bugzilla 和 JIRA 整合,快速測試計劃和執行搜尋,針對每個計劃、執行和案例以及 X
1359:圍成面積------有錯誤,80'
#include<iostream> #include<cstdio> using namespace std; int flag[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; int a[1000][1000]; int qu
解決方法——Qt5中漢字顯示亂碼,出現錯誤“常量中有換行符”
第一步:在QT中,工具-選項-文字編輯器-檔案編碼-UTF-8 BOM中選擇“如果編碼是utf-8則新增” 第二步:在程式碼中將漢字重新敲一遍(敲幾個字即可) 第三步:(解決亂碼) 原始碼:chart->setTitle(“實