DrawerLayout侧滑简单应用
来源:互联网 发布:被淘宝卖家投诉怎么办 编辑:程序博客网 时间:2024/05/22 05:02
//布局将原来的更改为android.support.v4.widget.DrawerLayout
<android.support.v4.widget.DrawerLayout android:id="@+id/drawerlayout" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.mydrawerlayout.MainActivity">
//帧布局 <FrameLayout android:id="@+id/frame" android:layout_width="match_parent" android:layout_height="match_parent"/> <LinearLayout android:gravity="bottom" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:id="@+id/lw" android:layout_width="100dp" android:layout_height="40dp" android:layout_marginLeft="20dp" android:text="联网"/> <Button android:id="@+id/dtm" android:layout_width="100dp" android:layout_height="40dp" android:layout_marginLeft="40dp" android:text="多条目"/> <Button android:id="@+id/sxl" android:layout_width="100dp" android:layout_height="40dp" android:layout_marginLeft="40dp" android:button="@null" android:text="上下拉"/> </LinearLayout> <!-- 和drawerLayout配合需要配这两个属性 android:layout_gravity="left" android:choiceMode="singleChoice" -->//滑动出来的内容<LinearLayout android:id="@+id/ll" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" android:choiceMode="singleChoice"> <ImageView android:id="@+id/img" android:layout_width="100dp" android:layout_height="100dp" android:src="@mipmap/fruit2"/> <ListView android:id="@+id/lv" android:background="@color/colorAccent" android:layout_width="200dp" android:layout_height="match_parent"/> </LinearLayout></android.support.v4.widget.DrawerLayout>
//Main方法
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取控件 initView(); //drawerlayout里面lv适配器 initData(); //点击listview监听并且更改帧布局 setListener(); //获得自定义的frament add();}private void initView() {// vp = (ViewPager) findViewById(R.id.vp); drawerlayout = (DrawerLayout) findViewById(R.id.drawerlayout); frame = (FrameLayout) findViewById(R.id.frame); lv = (ListView) findViewById(R.id.lv); ll = (LinearLayout) findViewById(R.id.ll);}private void initData() { //drawerlayout里面lv适配器 arr = new ArrayList<>(); for (int i = 0; i < 5; i++) { arr.add("chenxu"+i); } ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, arr); lv.setAdapter(arrayAdapter);}//点击listview的条目,把名字赋值到帧布局上private void setListener() {
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { frament = new frament(); Bundle bundle = new Bundle(); bundle.putString("name",arr.get(i)); frament.setArguments(bundle); //添加帧布局 getSupportFragmentManager().beginTransaction().replace(R.id.frame,frament).commit(); //关闭drawer drawerlayout.closeDrawer(R.layout.activity_main); } });
阅读全文
0 0
- DrawerLayout侧滑简单应用
- Android DrawerLayout简单应用
- DrawerLayout实现简单的侧滑功能
- 最简单的侧滑效果DrawerLayout
- Android DrawerLayout简单实现侧滑菜单
- Android-------DrawerLayout实现简单侧滑
- 最简单DrawerLayout侧滑菜单
- DrawerLayout侧滑菜单的简单实现
- DrawerLayout(官方侧滑菜单)的简单使用(转载)
- 使用DrawerLayout实现简单的侧滑效果
- Android DrawerLayout 侧滑界面的简单实现
- 利用ToolBar和Drawerlayout实现简单的侧滑菜单
- android 最简单的侧滑实现DrawerLayout
- 侧滑菜单的简单实现(DrawerLayout+Toolbar+NavigationView)
- Android 侧滑菜单DrawerLayout简单的使用_田少嵩
- DrawerLayout配合NavigationView简单实现侧滑菜单栏
- 官方侧滑菜单DrawerLayout的简单实现
- DrawerLayout(官方侧滑菜单)的简单使用
- sql主键的一种形成方式
- 全选案例思维理解
- mySQL之关键字的执行优先级
- 泰牛php程序员thinkphp5视频教程,韩顺平thinkphp5视频教程,2017年最新thinkphp5视频教程
- Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"报错
- DrawerLayout侧滑简单应用
- Server Tomcat v7.0 Server at localhost failed to start
- caffe 使用中遇到的问题
- SpringMVC注解中@Controller和@RestController的区别
- Nginx+Tomcat7+redis实现session共享
- Java-线程创建的几种方式
- java反射
- Xcode9如何push到远程git仓库
- Red Hat CloudForms REST API 学习(二)