推荐条+fragment

主布局


package com.example.dell.day1215;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.example.dell.day1215.adapter.MyAdapter;

public class MainActivity extends AppCompatActivity {

    private ViewPager viewPager;
    private TabLayout tab;
    private MyAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();

    }

    private void initData() {
        //添加适配器
        adapter = new MyAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        tab.setupWithViewPager(viewPager);
    }

    private void initView() {
        //寻找资源id
        viewPager = findViewById(R.id.viewpager);
        tab = findViewById(R.id.tab);
    }
}

适配器

开始适配器


package com.example.dell.day1215.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.example.dell.day1215.fragment.AFragment;
import com.example.dell.day1215.fragment.BFragment;

public class MyAdapter extends FragmentPagerAdapter {
    private String[] menues=new String[]{
      "电影","资讯","视频","我的"
    };
    public MyAdapter(FragmentManager fm) {
        super(fm);
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return menues[position];
    }

    @Override
    public Fragment getItem(int i) {
        switch (i){
            case 0:
                return new AFragment();
            case 1:
                return new BFragment();
            case 2:
                return new BFragment();
                default:
                    return new BFragment();
        }

    }

    @Override
    public int getCount() {
        return menues.length;
    }
}

子适配器


package com.example.dell.day1215.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.example.dell.day1215.fragment.aAFragment;
import com.example.dell.day1215.fragment.aBFragment;

public class aMyAdapter extends FragmentPagerAdapter {
    //定义集合
    private String[] menu=new String[]{
            "正在上映","即将上映"
    };
    public aMyAdapter(FragmentManager fm) {
        super(fm);
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return menu[position];
    }

    @Override
    public Fragment getItem(int i) {
        switch (i){
            case 0:
                return new aAFragment();
            case 1:
                return new aBFragment();
        }
        return null;
    }

    @Override
    public int getCount() {
        return menu.length;
    }
}

list加载适配器


package com.example.dell.day1215.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dell.day1215.Bean.MovieBean;
import com.example.dell.day1215.R;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

public class LISTVIEWBaseAdapter extends BaseAdapter {
    private Context context;
    private List<MovieBean.ResultBean> list;

    public LISTVIEWBaseAdapter(Context context) {
        this.context = context;
        list=new ArrayList<>();
    }
    //更新数据
    public void setList(List<MovieBean.ResultBean> list1) {
        list.clear();
        if (list1!=null){
            this.list = list1;
        }
        notifyDataSetChanged();
    }
   //追加数据
    public void addData(List<MovieBean.ResultBean> d){
        if (d!=null){
            list.addAll(d);
        }
        notifyDataSetChanged();
    }
    @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;
        if (convertView==null){
             holder = new ViewHolder();
            convertView=LayoutInflater.from(context).inflate(R.layout.list,parent,false);
            holder.img=convertView.findViewById(R.id.img);
            holder.text=convertView.findViewById(R.id.text);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.text.setText(list.get(position).getName());
        ImageLoader.getInstance().displayImage(list.get(position).getImageUrl(),holder.img);
        return convertView;
    }
    class ViewHolder{
        ImageView img;
        TextView text;
    }
}

list2适配器


package com.example.dell.day1215.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dell.day1215.Bean.MovieBean;
import com.example.dell.day1215.R;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

public class LISTVIEWBaseAdapter2 extends BaseAdapter {

    private Context context;
    private List<MovieBean.ResultBean> blist;

    public LISTVIEWBaseAdapter2(Context context) {
        this.context = context;
        blist=new ArrayList<>();
    }

    public void setBlist(List<MovieBean.ResultBean> blist1) {
        blist.clear();
        if (blist1!=null){
            this.blist = blist;
        }
        notifyDataSetChanged();
    }
   public void addDatab(List<MovieBean.ResultBean> n){
        if (n!=null){
            blist.addAll(n);
        }
        notifyDataSetChanged();
   }
    @Override
    public int getCount() {
        return blist.size();
    }

    @Override
    public Object getItem(int position) {
        return blist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder2 holder;
        if (convertView==null){
            holder = new LISTVIEWBaseAdapter2.ViewHolder2();
            convertView=LayoutInflater.from(context).inflate(R.layout.list,parent,false);
            holder.img=convertView.findViewById(R.id.img);
            holder.text=convertView.findViewById(R.id.text);
            convertView.setTag(holder);
        }else{
            holder = (LISTVIEWBaseAdapter2.ViewHolder2) convertView.getTag();
        }
        holder.text.setText(blist.get(position).getName());
        ImageLoader.getInstance().displayImage(blist.get(position).getImageUrl(),holder.img);
        return convertView;
    }
    class ViewHolder2{
        ImageView img;
        TextView text;
    }
}

Bean类


package com.example.dell.day1215.Bean;

import java.util.List;

public class MovieBean {
    private String message;
    private String status;
    private List<ResultBean> result;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public List<ResultBean> getResult() {
        return result;
    }

    public void setResult(List<ResultBean> result) {
        this.result = result;
    }

    public static class ResultBean {

        private boolean followMovie;
        private int id;
        private String imageUrl;
        private String name;
        private int rank;
        private String summary;

        public boolean isFollowMovie() {
            return followMovie;
        }

        public void setFollowMovie(boolean followMovie) {
            this.followMovie = followMovie;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getImageUrl() {
            return imageUrl;
        }

        public void setImageUrl(String imageUrl) {
            this.imageUrl = imageUrl;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getRank() {
            return rank;
        }

        public void setRank(int rank) {
            this.rank = rank;
        }

        public String getSummary() {
            return summary;
        }

        public void setSummary(String summary) {
            this.summary = summary;
        }
    }
}

fragment


package com.example.dell.day1215.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.dell.day1215.R;
import com.example.dell.day1215.adapter.aMyAdapter;

public class AFragment extends Fragment {

    private TabLayout atab;
    private ViewPager aviewpager;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment1, container, false);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        atab = view.findViewById(R.id.atab);
        aviewpager = view.findViewById(R.id.aviewpager);
        //设置适配器
        aMyAdapter adapter = new aMyAdapter(getChildFragmentManager());
        aviewpager.setAdapter(adapter);
        atab.setupWithViewPager(aviewpager);
    }
}

fragment1


package com.example.dell.day1215.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.dell.day1215.R;

public class BFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment2, container, false);
        return view;
    }
}

子fragment


package com.example.dell.day1215.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
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 android.widget.Toast;

import com.example.dell.day1215.Bean.MovieBean;
import com.example.dell.day1215.R;
import com.example.dell.day1215.adapter.LISTVIEWBaseAdapter;
import com.example.dell.day1215.util.NewUtil;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

public class aAFragment extends Fragment {

    private PullToRefreshListView pull;
    private LISTVIEWBaseAdapter adapter;
    private String uri="http://172.17.8.100/movieApi/movie/v1/findHotMovieList?count=10&page=";
    private int page=1;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.afragment1, container, false);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        pull = view.findViewById(R.id.pull);
        //添加适配器
        adapter = new LISTVIEWBaseAdapter(getContext());
        pull.setAdapter(adapter);

        pull.setMode(PullToRefreshBase.Mode.BOTH);
        pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {  //下载
              page=1;
              //初始化数据
              initData();
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {   //刷新
               initData();
               page++;
            }
        });
        initData();
    }

    private void initData() {
            NewUtil.requestData(uri + page, MovieBean.class, new NewUtil.CallBack<MovieBean>() {

                @Override
                public void onsuccess(MovieBean nowBean) {
                  if (nowBean.getResult().size()==0){
                      pull.onRefreshComplete();
                      Toast.makeText(getActivity(),"没有数据",Toast.LENGTH_SHORT).show();
                  }
                  if (page==1){  //更新
                      adapter.setList(nowBean.getResult());
                  }else{        //追加
                      adapter.addData(nowBean.getResult());
                  }
                  page++;
                  pull.onRefreshComplete();
                }

            });
    }
}

子2布局


package com.example.dell.day1215.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
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 android.widget.Toast;

import com.example.dell.day1215.Bean.MovieBean;
import com.example.dell.day1215.R;
import com.example.dell.day1215.adapter.LISTVIEWBaseAdapter2;
import com.example.dell.day1215.util.NewUtil;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

public class aBFragment extends Fragment {
    private PullToRefreshListView pull;
    private String uri="http://172.17.8.100/movieApi/movie/v1/findHotMovieList?count=10&page=";
    private int page=1;
    private LISTVIEWBaseAdapter2 adapter2;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.afragment1, container, false);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        pull = view.findViewById(R.id.pull);
        //添加适配器
        adapter2 = new LISTVIEWBaseAdapter2(getContext());
        pull.setAdapter(adapter2);

        pull.setMode(PullToRefreshBase.Mode.BOTH);
        pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {  //下载
                page=1;
                //初始化数据
                initData();
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {   //刷新
                initData();
                page++;
            }
        });
        initData();
    }

    private void initData() {
        NewUtil.requestData(uri + page, MovieBean.class, new NewUtil.CallBack<MovieBean>() {

            @Override
            public void onsuccess(MovieBean downBean) {
                if (downBean.getResult().size()==0){
                    pull.onRefreshComplete();
                    Toast.makeText(getActivity(),"没有数据",Toast.LENGTH_SHORT).show();
                }
                if (page==1){  //更新
                   adapter2.setBlist(downBean.getResult());
                }else{        //追加
                    adapter2.addDatab(downBean.getResult());
                }
                page++;
                pull.onRefreshComplete();
            }

        });
    }
}

sqi类


package com.example.dell.day1215.sqilite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class SQLiteHelper extends SQLiteOpenHelper {

    public SQLiteHelper(Context context) {
        super(context,"User.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
     db.execSQL("create table data(id integer primary key autoincrement," +
             "title text," +
             "summary text," +
             "image_url text)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

util


package com.example.dell.day1215.util;

import android.annotation.SuppressLint;
import android.os.AsyncTask;

import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;

public class NewUtil {
    public interface CallBack<T>{
        void onsuccess(T t);
    }
    @SuppressLint("StaticFieldLeak")
    public static void requestData(String e, final Class calzz, final CallBack callBack){
        new AsyncTask<String,Void,Object>(){

            @Override
            protected Object doInBackground(String... strings) {
                return requestData(strings[0],calzz);
            }

            @Override
            protected void onPostExecute(Object o) {
                callBack.onsuccess(o);
            }
        }.execute(e);
    }

    private static <T> T requestData(String string, Class calzz) {
        return(T) new Gson().fromJson(requestData(string),calzz);
    }

    private static String requestData(String string) {
        try {
            URL url = new URL(string);
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setConnectTimeout(5000);
            urlConnection.setReadTimeout(5000);
            int responseCode = urlConnection.getResponseCode();
            if (responseCode==200){
                String result=stream2String(urlConnection.getInputStream());
                return result;
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    private static String stream2String(InputStream inputStream) throws IOException {
        StringBuilder stringBuilder = new StringBuilder();
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
        for (String tmp=br.readLine();tmp!=null;tmp=br.readLine()){
            stringBuilder.append(tmp);
        }
        return stringBuilder.toString();
    }
}

APP设置图片


package com.example.dell.day1215;

import android.app.Application;
import android.graphics.Bitmap;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        ImageLoaderConfiguration loaderConfiguration = new ImageLoaderConfiguration.Builder(this)
                .memoryCacheSize(10)
                .diskCacheSize(10 * 1024 * 1024)
                .defaultDisplayImageOptions(new DisplayImageOptions.Builder()
                        .bitmapConfig(Bitmap.Config.RGB_565)
                        .showImageOnLoading(R.mipmap.ic_launcher)
                        .showImageOnFail(R.mipmap.ic_launcher)
                        .showImageForEmptyUri(R.mipmap.ic_launcher)
                        .cacheOnDisk(true)
                        .cacheInMemory(true)
                        .build()
                ).build();
        ImageLoader.getInstance().init(loaderConfiguration);
    }
}

抽取类


package com.example.dell.day1215;

import android.content.Context;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;
import android.view.View;

public abstract class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
        initView();
    }
    protected abstract void initView();
    protected abstract void initData();
}

布局viewPager+Fragment+侧拉


<?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"

    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_weight="1"
            android:background="#ff00"
            android:layout_width="match_parent"
            android:layout_height="700dp">
        </android.support.v4.view.ViewPager>
        <android.support.design.widget.TabLayout
            android:id="@+id/tab"
            app:tabMode="fixed"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ff99"
            ></android.support.design.widget.TabLayout>
    </LinearLayout>
    <LinearLayout
        android:id="@+id/cela"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_gravity="start"
        android:background="#f0f0">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:src="@mipmap/ic_launcher"
            />
        <LinearLayout
            android:layout_gravity="center"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <TextView
                android:id="@+id/text01"
                android:layout_weight="1"
                android:textSize="30dp"
                android:text="设置头像"
                android:layout_gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            <TextView
                android:id="@+id/text02"
                android:layout_weight="1"
                android:textSize="30dp"
                android:text="放大电路"
                android:layout_gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            <TextView
                android:id="@+id/text03"
                android:layout_weight="1"
                android:textSize="30dp"
                android:text="公开规范"
                android:layout_gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

TabLayout+ViewPager


<?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"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <android.support.design.widget.TabLayout
        android:id="@+id/atab"
        app:tabMode="fixed"
        android:background="#0f0"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.design.widget.TabLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/aviewpager"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#f679"
        ></android.support.v4.view.ViewPager>
</LinearLayout>

来源:https://blog.csdn.net/jiaxiaofei622/article/details/85013037

原文地址:https://www.cnblogs.com/thatme/p/10192952.html

时间: 2024-10-17 06:04:34

推荐条+fragment的相关文章

【Android UI设计与开发】第07期:底部菜单栏(二)Fragment的详细介绍和使用方法

转载请注明出处:http://blog.csdn.net/yangyu20121224/article/details/8995025 由于TabActivity在Android4.0以后已经被完全弃用,那么我就不再浪费口水继续讲解它了,取而代之的是Fragment.Fragment是Android3.0新增的概念,Fragment翻译成中文是碎片的意思,不过却和Activity十分的相似,这一篇我花大量的篇幅来详细的讲解Fragment的介绍和使用方法. 一.Fragment的基础知识介绍  

【转】【Android UI设计与开发】第07期:底部菜单栏(二)Fragment的详细介绍和使用方法

原始地址:http://blog.csdn.net/yangyu20121224/article/category/1431917/1 由于TabActivity在Android4.0以后已经被完全弃用,那么我就不再浪费口水继续讲解它了,取而代之的是Fragment.Fragment是Android3.0新增的概念,Fragment翻译成中文是碎片的意思,不过却和Activity十分的相似,这一篇我花大量的篇幅来详细的讲解Fragment的介绍和使用方法. 一.Fragment的基础知识介绍  

Activity,Fragment状态保存

Activity android:alwaysRetainTaskState     用法 用来标记Activity所在的Task的状态是否总是由系统来保持--"true",表示总是:"false",表示在某种情形下允许系统恢复Task 到它的初始化状态.默认值是"false".这个特性只针对Task的根Activity有意义:对其它Activity来说,忽略之.     一般来说,特定的情形如当用户从主画面重新选择这个Task时,系统会对这个T

初学Fragment

以前自己做的应用呢,及时比较小的,然后没有现在布局需要用到,或者布局的复杂程度高.所以,现在来看看这个简单的Fragment,也就好似Activity了.其实我们要做的一些大界面都推荐用Fragment吧.其实Activity肯定没有Fragment的广泛. 为了找到与Activity的共同点,所以,我用的是一个大的布局中,引用的两个Fragment,一个是类似于Activity中的List继承系统的ListActivity一样,继承的ListFragment,然后,其实这里我们也可以直接在布局

Android开发笔记(10)——使用Fragment传递

转载请注明:http://www.cnblogs.com/igoslly/p/6911165.html 由于最近废寝忘食地在开发App,没来得及及时做总结,没有用很高级的部件,勉强也使用一些功能完成了自己的第一个App,撒花~~~ 接下来都是自己在开发中使用后的一些经验,也是和他人学习实践后的成果,主要是关于Fragment. /* 添加Fragment有静态添加 & 动态添加两种方式 * 静态是在Layout布局中添加<Fragment>控件 * 由于可以设置id,则可通过id寻找

Android ViewPager+Fragment滑动选项卡,tab点击选项卡

有一段时间一直再研究这个,自Android 3.0以后,很少开发者再用以前的TabWidget控件了.那种效果不是很好,也不能滑动.后来陆续出现了各种各样滑动选项卡,每种的出现都各有优势吧.但我还是推荐ViewPager+Fragment滑动选项卡,tab点击选项卡.因为横屏或者竖屏效果都还不错,针对这种效果,还有一种开源框架的出现.接下来会有所介绍. 转载请注明出处:http://blog.csdn.net/qq_16064871 本文demo下载:请点击 一.ViewPagerActivit

Android应用经典主界面框架之一:仿QQ (使用Fragment, 附源码)

最近反复研究日常经典必用的几个android app,从主界面带来的交互方式入手进行分析,我将其大致分为三类.今天记录第一种方式,即主界面下面有几个tab页,最上端是标题栏,tab页和tab页之间不是通过滑动切换的,而是通过点击切换tab页.早期这种架构一直是使用tabhost+activitygroup来使用,随着fragment的出现及google官方也大力推荐使用fragment,后者大有代替前者之势.本文也使用fragment进行搭建,标题中的"经典"指这种交互经典,非本文的代

Fragment.setArguments()

在我们平常开发的时候Fragment是经常使用的,而我们创建一个Fragment对象的时候一般都会 通过 new Fragment()构造方法来实现,如果要传递参数我们一般会重载构造方法,例如 new Fragment(Parameter p). 但是这样的做法是不被提倡的,如果你重载构造函数之后,系统会有一个warning,如下: Avoid non-default constructors in fragments: use a default constructor plus Fragme

android Fragment入门

Fragment是android3.0引入的,为什么google推出Fragment呢?主要目的是用在大屏幕设备上--例如平板电脑上,支持更加动态和灵活的UI设计.平板电脑的屏幕要比手机的大得多,有更多的空间来放更多的UI组件,并且这些组件之间会产生更多的交互,Fragment允许这样的一种设计,而不需要你亲自来管理 viewhierarchy的复杂变化. 通过将activity的布局分散到fragment中, 你可以在运行时修改activity的外观,可以把Fragment看作是activit