DrawLayout
来源:互联网 发布:空军一号 国际歌 知乎 编辑:程序博客网 时间:2024/06/05 10:23
<1>、xml布局代码
<android.support.v4.widget.DrawerLayout
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"
android:id="@+id/dl">
<FrameLayout
android:id="@+id/fl"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<ListView
android:layout_width="240dp"
android:layout_height="match_parent"
android:id="@+id/lv"
android:background="#00ff00"
android:layout_gravity="start"
android:choiceMode="singleChoice"></ListView>
</android.support.v4.widget.DrawerLayout>
<2>、MainActivity代码
public classMainActivityextendsAppCompatActivity {
privateList<String>list;
privateDrawerLayoutdl;
@Override
protected voidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initDate();
dl= (DrawerLayout) findViewById(R.id.dl);
FrameLayout fl= (FrameLayout) findViewById(R.id.fl);
finalListView lv= (ListView) findViewById(R.id.lv);
lv.setAdapter(newMyAdapter());
lv.setOnItemClickListener(newAdapterView.OnItemClickListener() {
@Override
public voidonItemClick(AdapterView<?> parent, View view,intposition,longid) {
//String string= (String) parent.getItemAtPosition(position);
ContentFragment contentFragment =newContentFragment();
Bundle bundle=newBundle();
bundle.putString("name",list.get(position));
contentFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.fl,contentFragment).commit();
dl.closeDrawer(lv);
}
});
}
private voidinitDate() {
list=newArrayList<>();
for(inti=0;i<5;i++){
list.add("item"+i);
}
}
classMyAdapterextendsBaseAdapter{
@Override
public intgetCount() {
returnlist.size();
}
@Override
publicObject getItem(intposition) {
return null;
}
@Override
public longgetItemId(intposition) {
return0;
}
@Override
publicView getView(intposition, View convertView, ViewGroup parent) {
TextView tv =newTextView(MainActivity.this);
tv.setText(list.get(position));
tv.setTextSize(25);
returntv;
}
}
}
<3>、Fragment类代码
public classContentFragmentextendsFragment{
@Nullable
@Override
publicView onCreateView(LayoutInflater inflater,@NullableViewGroup container,@NullableBundle savedInstanceState) {
Bundle bundle = getArguments();
String name = bundle.getString("name");
TextView textView =newTextView(getActivity());
textView.setText(name);
returntextView;
}
}
阅读全文
0 0
- DrawLayout
- DrawLayout
- Drawlayout
- DrawLayout
- drawlayout
- drawlayout侧滑
- DrawLayout的使用
- 抽屉效果(DrawLayout)
- drawlayout的使用
- DrawLayout 侧滑侧栏点击穿透
- drawlayout的使用
- drawlayout(二)
- Drawlayout 抽屉 禁用滑动
- DrawLayout侧拉
- DrawLayout的简单使用
- drawlayout侧拉
- DrawLayout的使用
- DrawLayout的使用
- 判断网络
- ng-option
- web service 对外发布一个hello world接口(入门)
- LCS,LCIS,LIS模板
- redis乐观锁实现秒杀
- DrawLayout
- 技术的正宗与野路子
- IT行业offer分析
- 双倍回文
- C++ const总结
- 堆排序
- [kuangbin带你飞]专题十六 KMP & 扩展KMP
- 访问private函数的方法
- makefile 中 $@ $^ %< 使用