DrawerLayout侧滑
来源:互联网 发布:linux下vim配置文件 编辑:程序博客网 时间:2024/06/14 14:09
xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="animtest.com.example.e531.drawerlayout_demo.MainActivity">
<!--侧拉菜单-->
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drlayout">
<!--主页面的布局使用DrawerLayout要记得导入依赖-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fcontent">
</FrameLayout>
<!--侧拉菜单的布局 android:layout_gravity="start" 菜单在左边 end 菜单在右边 -->
<RelativeLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#ffff00"
android:id="@+id/rel">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:id="@+id/img"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv"
android:layout_below="@id/img"></ListView>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
<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"
tools:context="animtest.com.example.e531.drawerlayout_demo.MainActivity">
<!--侧拉菜单-->
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drlayout">
<!--主页面的布局使用DrawerLayout要记得导入依赖-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fcontent">
</FrameLayout>
<!--侧拉菜单的布局 android:layout_gravity="start" 菜单在左边 end 菜单在右边 -->
<RelativeLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#ffff00"
android:id="@+id/rel">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:id="@+id/img"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv"
android:layout_below="@id/img"></ListView>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="我是主页面"
android:id="@+id/tvv"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="我是主页面"
android:id="@+id/tvv"/>
</LinearLayout>
Main
package animtest.com.example.e531.drawerlayout_demo;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private ListView listView;
private DrawerLayout drawerLayout;
private RelativeLayout rel;
private List<String> datas;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//查找组件
drawerLayout = (DrawerLayout) findViewById(R.id.drlayout);
listView = (ListView) findViewById(R.id.lv);
rel = (RelativeLayout) findViewById(R.id.rel);
//构造数据
datas = new ArrayList<String>();
for(int i=0;i<10;i++){
datas.add("菜单"+i);
}
//设置数组适配器
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, datas);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//关闭侧滑菜单
drawerLayout.closeDrawer(rel);
//drawerLayout.openDrawer(rel);//打开侧滑菜单
//设置参数
ContentFragment contentFragment=new ContentFragment();
Bundle bundle=new Bundle();
bundle.putString("value",datas.get(position));
contentFragment.setArguments(bundle);
//切换fragment
getSupportFragmentManager().beginTransaction().replace(R.id.fcontent,contentFragment).commit();
}
});
drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
//slideOffset:侧滑菜单 宽度的像素值
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
@Override
public void onDrawerOpened(View drawerView) {
Log.d("zzz","open");
}
@Override
public void onDrawerClosed(View drawerView) {
Log.d("zzz","close");
}
@Override
public void onDrawerStateChanged(int newState) {
Log.d("zzz","状态改变:"+newState);
}
});
}
}
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private ListView listView;
private DrawerLayout drawerLayout;
private RelativeLayout rel;
private List<String> datas;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//查找组件
drawerLayout = (DrawerLayout) findViewById(R.id.drlayout);
listView = (ListView) findViewById(R.id.lv);
rel = (RelativeLayout) findViewById(R.id.rel);
//构造数据
datas = new ArrayList<String>();
for(int i=0;i<10;i++){
datas.add("菜单"+i);
}
//设置数组适配器
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, datas);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//关闭侧滑菜单
drawerLayout.closeDrawer(rel);
//drawerLayout.openDrawer(rel);//打开侧滑菜单
//设置参数
ContentFragment contentFragment=new ContentFragment();
Bundle bundle=new Bundle();
bundle.putString("value",datas.get(position));
contentFragment.setArguments(bundle);
//切换fragment
getSupportFragmentManager().beginTransaction().replace(R.id.fcontent,contentFragment).commit();
}
});
drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
//slideOffset:侧滑菜单 宽度的像素值
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
@Override
public void onDrawerOpened(View drawerView) {
Log.d("zzz","open");
}
@Override
public void onDrawerClosed(View drawerView) {
Log.d("zzz","close");
}
@Override
public void onDrawerStateChanged(int newState) {
Log.d("zzz","状态改变:"+newState);
}
});
}
}
Fragment
package animtest.com.example.e531.drawerlayout_demo;
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;
/**
* Created by e531 on 2017/10/13.
*/
public class ContentFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v=View.inflate(getActivity(),R.layout.item,null);
TextView tvv= (TextView) v.findViewById(R.id.tvv);
String value=getArguments().getString("value");
tvv.setText(value);
return v;
}
}
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;
/**
* Created by e531 on 2017/10/13.
*/
public class ContentFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v=View.inflate(getActivity(),R.layout.item,null);
TextView tvv= (TextView) v.findViewById(R.id.tvv);
String value=getArguments().getString("value");
tvv.setText(value);
return v;
}
}
阅读全文
0 0
- 侧滑DrawerLayout
- DrawerLayout侧滑
- 侧滑Drawerlayout
- drawerlayout侧滑
- DrawerLayout 侧滑
- DrawerLayout侧滑
- drawerLayout 侧滑
- DrawerLayout侧滑
- drawerlayout侧滑
- .drawerlayout侧滑
- Android DrawerLayout 侧滑
- ANDROID drawerlayout+fragment侧滑
- DrawerLayout 抽屉效果 侧滑
- android--UI---侧滑drawerLayout
- DrawerLayout——侧滑
- DrawerLayout——侧滑
- 侧滑drawerlayout的使用
- 二包Drawerlayout 侧滑
- 跳跃游戏一(动态规划)
- ######纯注解ssh环境:crm系统===重点总结 概述(只有思想)
- 我的第一个程序
- listview_item02.xml
- Tablayout的基础使用
- DrawerLayout侧滑
- xlistview_footer.xml
- 感觉
- 使用recyclerview多条目加载代替listview okhttp请求网路 Glide加载图片
- xlistview_header.xml
- XListView下拉时间刷新代码
- Milk(emmmmm)
- DrawerLayout侧滑+Image-Loader+XListView+上拉下拉 Y
- 堆排序