fragment+viewpager+侧拉
来源:互联网 发布:微软雅黑bold for mac 编辑:程序博客网 时间:2024/05/22 10:54
xml:
<android.support.v4.widget.DrawerLayout android:id="@+id/mydrawer" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/frame" ></FrameLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/rel_navigate" android:layout_alignParentBottom="true"> <RadioButton android:id="@+id/but1" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="首页" android:button="@null" android:gravity="center"/> <RadioButton android:id="@+id/but2" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="视频" android:button="@null" android:gravity="center"/> <RadioButton android:id="@+id/but3" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="我的" android:button="@null" android:gravity="center"/> </RadioGroup> </RelativeLayout> <RelativeLayout android:layout_width="260dp" android:layout_height="match_parent" android:id="@+id/rel_menu" android:layout_gravity="start" android:background="#550000ff"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/img_title" android:background="@mipmap/ic_launcher"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="sssssss" android:layout_below="@+id/img_title"/> </RelativeLayout></android.support.v4.widget.DrawerLayout>
Activity:
public class MainActivity extends AppCompatActivity { private RadioButton b1; private RadioButton b2; private RadioButton b3; private Fragment1 fragment1; private Fragment2 fragment2; private Fragment3 fragment3; private DrawerLayout drawelauout; private ImageView imgTitle; private RelativeLayout relMenu; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); drawelauout = (DrawerLayout) findViewById(R.id.mydrawer); imgTitle = (ImageView) findViewById(R.id.img_title); relMenu = (RelativeLayout) findViewById(R.id.rel_menu); b1 = (RadioButton) findViewById(R.id.but1); b2 = (RadioButton) findViewById(R.id.but2); b3 = (RadioButton) findViewById(R.id.but3); fragment1 = new Fragment1(); fragment2 = new Fragment2(); fragment3 = new Fragment3(); getSupportFragmentManager().beginTransaction().add(R.id.frame,fragment1).commit(); getSupportFragmentManager().beginTransaction().add(R.id.frame,fragment2).commit(); getSupportFragmentManager().beginTransaction().add(R.id.frame,fragment3).commit(); hide(); getSupportFragmentManager().beginTransaction().show(fragment1).commit(); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { hide(); getSupportFragmentManager().beginTransaction().show(fragment1).commit(); } }); b2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { hide(); getSupportFragmentManager().beginTransaction().show(fragment2).commit(); } }); b3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { hide(); getSupportFragmentManager().beginTransaction().show(fragment3).commit(); } }); initdata(); } private void initdata() { imgTitle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //关闭,侧滑菜单 drawelauout.closeDrawer(relMenu); } }); } private void hide() { getSupportFragmentManager().beginTransaction().hide(fragment1).commit(); getSupportFragmentManager().beginTransaction().hide(fragment2).commit(); getSupportFragmentManager().beginTransaction().hide(fragment3).commit(); }}
阅读全文
0 0
- fragment+viewpager+侧拉
- ViewPager+Fragment+侧拉
- 侧拉+xlistview+Fragment+Viewpager+判断网络状态
- RadioGroup+Fragment+PulltorefreshScrollView+GridView+侧拉菜单+TabLayout+ViewPager
- fragment+侧拉
- Fragment+ViewPager
- Viewpager&Fragment
- viewpager + fragment
- viewpager+fragment
- viewpager+fragment
- ViewPager+Fragment
- viewPager+fragment
- ViewPager+Fragment
- ViewPager+Fragment
- viewpager+fragment
- Fragment+ViewPager
- ViewPager+Fragment
- Fragment+ViewPager
- Java发展史
- uva170
- 解决symbol(s) not found for architecture x86_64报错
- centos 6.8 下python2.6 升级python2.7,安装pip工具
- Unity相机自身围绕(第一人称视角)
- fragment+viewpager+侧拉
- 自定义 标题栏
- spring jaxb Object XML转换
- tf.train.batch()
- MP4转.JPG
- 当年校招时,我就死在这个问题上...
- Leetcode 551 Student Attendance Record I
- JVM类加载机制详细解析
- Android 8.0新特性适配测试报告来啦!