fragment001的使用
来源:互联网 发布:文明6 mac 下载 编辑:程序博客网 时间:2024/05/19 14:17
main
<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.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/radio_group" />
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radio_01"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/radio_selector"
android:button="@null"
android:checked="true"
android:gravity="center"
android:padding="10dp"
android:text="微信" />
<RadioButton
android:id="@+id/radio_02"
style="@style/radioStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="通讯录" />
<RadioButton
android:id="@+id/radio_03"
style="@style/radioStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="发现" />
<RadioButton
android:id="@+id/radio_04"
style="@style/radioStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="我" />
</RadioGroup>
</RelativeLayout>
fragment
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#00ff00"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
mian文件
public class MainActivity extends FragmentActivity implements OnCheckedChangeListener {
private RadioGroup group;
private ViewPager pager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//去掉标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
group = (RadioGroup) findViewById(R.id.radio_group);
pager = (ViewPager) findViewById(R.id.view_pager);
//现在viewPager要展示的是fragment,,,当前页面必须继承FragmentActivity,,,设置适配器(朱门适用于fragment的适配器)
//FragmentPagerAdapter展示fragment的viewpager的适配器
pager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {//参数是fragment的管理员对象
@Override
public int getCount() {
// TODO Auto-generated method stub
return 4;
}
//返回当前展示的fragment
@Override
public Fragment getItem(int position) {
Fragment fragment = null;
switch (position) {
case 0://展示第一个fragment
fragment = new Fragment01();
break;
case 1://展示第2个fragment
fragment = new Fragment02();
break;
case 2://展示第3个fragment
fragment = new Fragment03();
break;
case 3://展示第4个fragment
fragment = new Fragment04();
break;
default:
break;
}
return fragment;//返回
}
});
//给viewPager设置监听
pager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
// 选中某一页的时候需要让group选中那一个button
group.check(group.getChildAt(arg0).getId());
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
}
//给group设置选中改变的监听事件
group.setOnCheckedChangeListener(this);
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio_01://需要viewpager去展示第一页
//pager.setCurrentItem(0);
//int item, boolean smoothScroll选中某一页的时候是否滑动过去,,,默认就是滑动
pager.setCurrentItem(0, false);//就不会滑动了
break;
case R.id.radio_02:
pager.setCurrentItem(1, false);
break;
case R.id.radio_03:
pager.setCurrentItem(2, false);
break;
case R.id.radio_04:
pager.setCurrentItem(3, false);
break;
default:
break;
}
}
}
fragment
package com.example.radiogroupfragmentdemo01.fragment;
import com.example.radiogroupfragmentdemo01.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment01 extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.i("----", "-----");
View view = inflater.inflate(R.layout.fragment_01, container, false);
return view;
}
}
- fragment001的使用
- GUID使用的使用
- ${}的使用
- 的使用
- @[],@()的使用
- ->的使用
- +、-、*、/、%的使用
- &&的使用
- %:的使用
- Makefile中使用$$的使用
- Makefile中使用$$的使用
- Red5的使用--使用日志
- prefernce的使用具体使用
- 【工具使用】git 的使用
- 关于使用AsyncTaskLoader的使用
- 使用CABasicAnimation的基本使用
- 使用RocketMQ的客户端使用
- gulp的使用基本使用
- 对字符串复制的初步认识
- 最短路径--算法
- 关于协方差矩阵在机器学习中的理解
- Java 常用工具类 Collections 源码分析
- java生成随机字符串
- fragment001的使用
- acm #define
- Git分支管理策略
- ambari离线方式安装Hive不能连接mysql和不能启动hive metastore&hiveserver2
- 播放器/短视频 SDK 架构设计
- play framework 框架事务分割
- 1042. Shuffling Machine (20)
- 约瑟夫问题,“遍历”思想.(C语言实现)
- 《电路计算C++与MATLAB》学习笔记(二)