zoukankan      html  css  js  c++  java
  • 每日总结

    1.DrawerLayout(官方侧滑菜单)的简单使用

    xml

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <FrameLayout
            android:id="@+id/ly_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
        <ListView
            android:id="@+id/list_left_drawer"
            android:layout_width="180dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="#080808"
            android:choiceMode="singleChoice"
            android:divider="#FFFFFF"
            android:dividerHeight="1dp" />
    
    </android.support.v4.widget.DrawerLayout>

    ContentFragment.java

    /**
     * Created by Jay on 2015/10/8 0008.
     */
    public class ContentFragment extends Fragment {
    
        private TextView tv_content;
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.fg_content, container, false);
            tv_content = (TextView) view.findViewById(R.id.tv_content);
            String text = getArguments().getString("text");
            tv_content.setText(text);
            return view;
        }
    }
    MainActivity.java
    drawer_layout = (DrawerLayout) findViewById(R.id.drawer_layout);
            list_left_drawer = (ListView) findViewById(R.id.list_left_drawer);
    
            menuLists = new ArrayList<Item>();
            menuLists.add(new Item(R.mipmap.iv_menu_realtime,"实时信息"));
            menuLists.add(new Item(R.mipmap.iv_menu_alert,"提醒通知"));
            menuLists.add(new Item(R.mipmap.iv_menu_trace,"活动路线"));
            menuLists.add(new Item(R.mipmap.iv_menu_settings,"相关设置"));
            myAdapter = new MyAdapter<Item>(menuLists,R.layout.item_list) {
                @Override
                public void bindView(ViewHolder holder, Item obj) {
                    holder.setImageResource(R.id.img_icon,obj.getIconId());
                    holder.setText(R.id.txt_content, obj.getIconName());
                }
            };
            list_left_drawer.setAdapter(myAdapter);
            list_left_drawer.setOnItemClickListener(this);
        }
    
    
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ContentFragment contentFragment = new ContentFragment();
            Bundle args = new Bundle();
            args.putString("text", menuLists.get(position).getIconName());
            contentFragment.setArguments(args);
            FragmentManager fm = getSupportFragmentManager();
            fm.beginTransaction().replace(R.id.ly_content,contentFragment).commit();
            drawer_layout.closeDrawer(list_left_drawer);
        }
    }
  • 相关阅读:
    Android批量插入数据库提升速度(9.9)
    Android中database所在文件夹路径(9.6)
    Eclipse更改默认工作环境编码为UTF-8(9.6)
    Android下Sqlite的使用(9.7)
    Android下ListView的分页(9.6)
    【转】Tarjan算法 资料合集
    【转】BYV--有向图强连通分量的Tarjan算法
    Codeforces Round #403---C题(DFS,树)
    codeforces#403—B题(二分,三分)
    【转】毛虫算法——尺取法
  • 原文地址:https://www.cnblogs.com/chenghaixiang/p/14909161.html
Copyright © 2011-2022 走看看