MainActivity.java

public class MainActivity extends Activity implements View.OnClickListener, ViewPager.OnPageChangeListener {    private RadioButton rb_my, rb_withdrawals;    private MyFragment mMyFragment;    private WithdrawalsFragment mWithdrawalsFragment;    private ViewPager vp_main;    private ArrayList mFragmentList;    private MyViewPagerAdapter mViewPagerAdapter;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);        findViews();        setListensers();        InitView();    }    protected void findViews() {        rb_withdrawals = (RadioButton) findViewById(R.id.rb_withdrawals);        rb_my = (RadioButton) findViewById(R.id.rb_my);        vp_main = (ViewPager) findViewById(R.id.vp_main);    }    @Override    public void onClick(View view) {        switch (view.getId()) {            case R.id.rb_withdrawals:                vp_main.setCurrentItem(0);                break;            case R.id.rb_my:                vp_main.setCurrentItem(1);                break;            default:                break;        }    }    protected void setListensers() {        rb_withdrawals.setOnClickListener(this);        rb_my.setOnClickListener(this);        vp_main.setOnPageChangeListener(this);    }    @Override    public void onPageScrollStateChanged(int arg0) {    }    @Override    public void onPageScrolled(int arg0, float arg1, int arg2) {    }    @Override    public void onPageSelected(int id) {        switch (id) {            case 0:                rb_withdrawals.setChecked(true);                break;            case 1:                rb_my.setChecked(true);                break;            default:                break;        }    }    private void addFragment() {        if (mWithdrawalsFragment == null) {            mWithdrawalsFragment = new WithdrawalsFragment();        }        if (mMyFragment == null) {            mMyFragment = new MyFragment();        }        if (mFragmentList == null) {            mFragmentList = new ArrayList();// 初始化数据            mFragmentList.add(mWithdrawalsFragment);            mFragmentList.add(mMyFragment);        }    }    private void setViewPager() {        if (mViewPagerAdapter == null) {            mViewPagerAdapter = new MyViewPagerAdapter(getSupportFragmentManager(), mFragmentList);            vp_main.setAdapter(mViewPagerAdapter);            vp_main.setOffscreenPageLimit(3);        }    }    private void InitView() {        addFragment();        setViewPager();    }}

activity_main.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"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@color/screen_bg"    tools:context=".activity.MainActivity">    <RadioGroup        android:id="@+id/rg_control_button"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_alignParentBottom="true"        android:background="@color/white"        android:orientation="horizontal"        android:paddingBottom="10dp"        android:paddingTop="10dp">        <RadioButton            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="@drawable/radio_tab_home"            android:button="@null"            android:textColor="@color/light_gray"            android:textSize="12dp"            android:visibility="gone"/>        <RadioButton            android:id="@+id/rb_withdrawals"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="@drawable/get_red_package_select"            android:button="@null"            android:textColor="@color/light_gray"            android:textSize="12dp" />        <RadioButton            android:id="@+id/rb_my"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="@drawable/radio_tab_my"            android:button="@null"            android:textColor="@color/light_gray"            android:textSize="12dp" />    RadioGroup>    <android.support.v4.view.ViewPager        android:id="@+id/vp_main"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_above="@id/rg_control_button"        android:flipInterval="30"        android:persistentDrawingCache="animation" />    <View        android:layout_width="match_parent"        android:layout_height="1dp"        android:layout_below="@id/vp_main"        android:background="#60777777" />RelativeLayout>

更多相关文章

  1. android > SMS 短信数据库访问
  2. Android(安卓)socket 工具类
  3. Android(安卓)自定义BaseRecyclerView.Adapter
  4. JNI基本数据类型转换
  5. Android(安卓)RSA 加密(分段加密)
  6. android:uploaddatatoWeb
  7. ch020 Android(安卓)SQLite3(第一部分)
  8. Android:SQLiteOpenHelper
  9. ch020 Android(安卓)SQLite3(第一部分)

随机推荐

  1. 实现Android多张图片选择
  2. Android(安卓)Canvas绘图详解【转】
  3. 使用SmsManager服务群发短信
  4. android中get方式和post方式提交数据到服
  5. Android代码内存优化建议-Android官方篇
  6. 检查网络连接状况
  7. 解决错误ERROR: No suitable Java found.
  8. android studio常用快捷键整理
  9. Android(安卓)Studio常用快捷键、Android
  10. 通过apk签名使应用程序有系统权限