drawerlayout使用
来源:互联网 发布:淘宝商品图片 编辑:程序博客网 时间:2024/05/19 09:41
//布局
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--主内容区域-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_above="@+id/radio_group"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<RadioGroup
android:id="@+id/radio_group"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp">
<RadioButton
android:id="@+id/radio_01"
android:padding="10dp"
android:button="@null"
android:gravity="center"
android:background="@drawable/radio_selector"
android:checked="true"
android:text="首页"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
<RadioButton
android:id="@+id/radio_02"
android:padding="10dp"
android:button="@null"
android:gravity="center"
android:background="@drawable/radio_selector"
android:text="视频"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
<RadioButton
android:id="@+id/radio_03"
android:padding="10dp"
android:button="@null"
android:gravity="center"
android:background="@drawable/radio_selector"
android:text="资讯"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
<RadioButton
android:id="@+id/radio_04"
android:padding="10dp"
android:button="@null"
android:gravity="center"
android:background="@drawable/radio_selector"
android:text="我的"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
</RadioGroup>
</RelativeLayout>
<!--侧滑菜单区域-->
<RelativeLayout
android:id="@+id/drawer_relative"
android:layout_gravity="start"
android:background="#ffffff"
android:layout_width="240dp"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image_touxiang"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@mipmap/ic_launcher"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
/>
<ListView
android:id="@+id/list_view_drawer"
android:layout_below="@+id/image_touxiang"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
//代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//跟布局
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
//抽屉布局
relativeLayout = (RelativeLayout) findViewById(R.id.drawer_relative);
//展示抽屉数据的listView
listView = (ListView) findViewById(R.id.list_view_drawer);
radioGroup = (RadioGroup) findViewById(R.id.radio_group);
//1.设置抽屉中listView的数据
List<String> list = new ArrayList<>();
list.add("客服热线");
list.add("客服热线");
list.add("客服热线");
list.add("客服热线");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,android.R.id.text1,list);
//设置奢配器
listView.setAdapter(adapter);
//2.radioGroup的监听事件
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i){
case R.id.radio_01:
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout,new FragmentHome()).commit();
break;
case R.id.radio_02:
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout,new FragmentVideo()).commit();
break;
case R.id.radio_03:
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout,new FragmentZiXun()).commit();
break;
case R.id.radio_04:
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout,new FragmentMy()).commit();
break;
default:
break;
}
}
});
//3.默认进入页面显示的是首页
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout,new FragmentHome()).commit();
}
}
- DrawerLayout 使用
- DrawerLayout 使用
- DrawerLayout使用
- DrawerLayout使用
- DrawerLayout使用
- drawerlayout使用
- DrawerLayout的基本使用
- Android - DrawerLayout的使用
- DrawerLayout的基本使用
- DrawerLayout控件的使用
- 学习使用DrawerLayout
- Android DrawerLayout的使用
- DrawerLayout的使用例子
- DrawerLayout使用一二事
- DrawerLayout的使用
- DrawerLayout的使用
- DrawerLayout的使用
- Android DrawerLayout的使用
- 数据挖掘sklearn中的的特征工程处理
- windows查看端口被占用以及关闭相关的进程
- 统计每个商品每个月的销量???
- ue4 retarge记录
- iRedMail Dovecot Master User
- drawerlayout使用
- 数据结构第九周项目——二叉树算法库
- CentOS6.5 安装、配置Solr
- 2017中国存储峰会七大论坛议题
- HTML5权威指南笔记:15-嵌入内容
- 快递单子
- pycharm中的console退出问题以及console和pycharm各自运行结果不一样的问题
- jenkins blueocean使用
- laravel 支付