DrawerLayout 侧滑
来源:互联网 发布:mysql编程题及答案 编辑:程序博客网 时间:2024/05/22 06:36
activity_main.xml<?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.example.fxf.drawerlayoutdemo2.MainActivity"> <FrameLayout android:id="@+id/fragment" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> <ListView android:id="@+id/listview" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="left" android:background="@color/colorAccent" android:choiceMode="singleChoice"></ListView></android.support.v4.widget.DrawerLayout>MianActivity.java
import android.os.Bundle;import android.support.v4.app.FragmentTransaction;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;import java.util.List;public class MainActivity extends AppCompatActivity { List<String> list = new ArrayList<>(); private DrawerLayout drawerLayout; private FrameLayout frameLayout; private ListView listview; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); initData(); SetLisente(); } //初始化 private void initView() { drawerLayout = (DrawerLayout) findViewById(R.id.drawerlayout); frameLayout = (FrameLayout) findViewById(R.id.fragment); listview = (ListView) findViewById(R.id.listview); } //DrawerLayout listview配完 private void initData() { for (int i = 0; i < 9; i++) { list.add("text" + i); } ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this , android.R.layout.simple_list_item_1, list); listview.setAdapter(adapter); } //点击DrawerLayout中 listview赋值到主页面fragment中TextVite中 private void SetLisente() { listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Fragment01 fragment01 = new Fragment01(); Bundle bundle = new Bundle(); bundle.putString("name", list.get(position)); fragment01.setArguments(bundle); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); FragmentTransaction replace = fragmentTransaction.replace(R.id.fragment, fragment01); replace.commit(); // 关闭DrawerLayout drawerLayout.closeDrawer(listview); } }); }}Fragment01.javapublic class Fragment01 extends Fragment { private View view; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment01, container, false); return view; } public void onActivityCreated( Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); TextView textView = (TextView) view.findViewById(R.id.fragment_textView); Bundle arguments = getArguments(); String name = arguments.getString("name"); textView.setText(name); }}加 fragment01.xml<?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:id="@+id/fragment_textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /></LinearLayout>
阅读全文
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 侧滑
- CSS(5)
- 【CUGBACM15级BC第32场 A】hdu 5182 PM2.5
- 1094:多输入输出练习2
- Linux 技巧:让进程在后台可靠运行的几种方法
- 深度卷积网络CNN与图像语义分割
- DrawerLayout 侧滑
- 51Nod- 1006 最长公共子序列Lcs(动态规划)
- 关于ffmpeg的一个bug长期求解答
- Elasticsearch&logstash&filebeat&kibana&x-pack搭建
- 深入理解HashSet
- [较难] UVa OJ 12174 Shuffle 滑动窗口
- decltype详解之指针类型的推断
- Jump Game II
- 学html5不得不说的html5shiv.js和pug