DrawerLayout侧滑栏
来源:互联网 发布:web数据挖掘第二版pdf 编辑:程序博客网 时间:2024/06/02 00:25
主界面
package com.wzq.drawerlayoutdemo2;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ListView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {private DrawerLayout drawerLayout;private FrameLayout frameLayout;private ListView lv;private ArrayList<String> lists;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); initData(); setListener();}private void initView() { drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); frameLayout = (FrameLayout) findViewById(R.id.frameLayout); lv = (ListView) findViewById(R.id.lv);}private void initData() { lists = new ArrayList<>(); for (int i = 0; i < 5; i++) { lists.add("DrawerLayout" + i); } ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, lists); lv.setAdapter(stringArrayAdapter);}private void setListener() { lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { MFragment mFragment = new MFragment(); Bundle bundle = new Bundle(); bundle.putString("name", lists.get(i)); mFragment.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout, mFragment).commit(); //关闭drawer drawerLayout.closeDrawer(lv); } }); }}
布局
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/drawerLayout"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.wzq.drawerlayoutdemo2.MainActivity"><FrameLayout android:id="@+id/frameLayout" android:layout_width="match_parent" android:layout_height="match_parent" /><!--和drawerLayout配合需要配这两个属性android:layout_gravity="left"从左侧拉出android:choiceMode="singleChoice"--><ListView android:id="@+id/lv" android:layout_width="300dp" android:layout_height="match_parent" android:layout_gravity="left" android:background="@color/colorPrimary" android:choiceMode="singleChoice" /></android.support.v4.widget.DrawerLayout>
侧滑页面
package com.wzq.drawerlayoutdemo2;
import android.os.Bundle;
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.TextView;
public class MFragment extends Fragment {@Nullable@Overridepublic View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstancState) { TextView textView = new TextView(getActivity()); Bundle arguments = getArguments(); String name = arguments.getString("name"); textView.setText(name); return textView; }}
阅读全文
0 0
- 侧滑栏Drawerlayout
- DrawerLayout侧滑栏
- DrawerLayout侧滑栏加载
- DrawerLayout侧滑栏简单使用
- DrawerLayout
- DrawerLayout
- DrawerLayout
- DrawerLayout
- DrawerLayout
- DrawerLayout
- DrawerLayout
- drawerLayout
- DrawerLayout
- DrawerLayout
- DrawerLayout
- DrawerLayout
- DrawerLayout
- DrawerLayout
- springMVC 执行流程
- HDU 6138 Fleet of the Eternal Throne AC自动机
- Idea导入项目及部署至Tomcat(从Eclipse到Idea的华丽转身)
- 关于jedis异常:Could not get a resource from the pool
- Thinkphp5 出现错误 require mongodb > 1.0
- DrawerLayout侧滑栏
- OPENGL学习笔记之三
- 关于V4L2编程中获取视频流的误区
- hdu4460-最短路&思维- Friend Chains
- 案例|FEC筷云经典案例“西洋街”,澳门最大跨境电商平台
- Object Detection--RCNN,SPPNet,Fast RCNN,FasterRCNN论文详解
- [JAVA] Hibernate 继承映射
- python虚拟环境的安装与配置
- spring 技术内幕读后感2---设计理念与整体架构