zoukankan      html  css  js  c++  java
  • 62、常规控件(5)Navigation View –美观的侧滑视图

    1、main_layout.xml

     1 <android.support.v4.widget.DrawerLayout
     2     xmlns:android="http://schemas.android.com/apk/res/android"
     3     xmlns:app="http://schemas.android.com/apk/res-auto"
     4     android:id="@+id/drawer_layout"
     5     android:layout_width="match_parent"
     6     android:layout_height="match_parent">
     7 
     8     <include layout="@layout/activity_main"/>
    10     <!--
    11         android:fitsSystemWindows="true|false":适合系统窗口
    12     -->
    14     <android.support.design.widget.NavigationView
    15         android:id="@+id/navigetion_view"
    16         android:layout_width="wrap_content"
    17         android:layout_height="match_parent"
    18         android:layout_gravity="left"
    19         android:fitsSystemWindows="true"
    20         app:headerLayout="@layout/head_view"
    21         app:menu="@menu/menu_main">
    24     </android.support.design.widget.NavigationView>
    25 
    26 </android.support.v4.widget.DrawerLayout>

    2、@layout/head_view  侧滑布局文件

     1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     android:layout_width="match_parent"
     3     android:layout_height="match_parent"
     4     android:gravity="center"
     5     android:orientation="vertical">
     6     <ImageView
     7         android:layout_width="wrap_content"
     8         android:layout_height="wrap_content"
     9         android:src="@drawable/ic_launcher"/>
    10 </LinearLayout>

    3、MainActivity.java

     1 package com.example.com.designdemo;
     2 
     3 import android.os.Bundle;
     4 import android.support.design.widget.TabLayout;
     5 import android.support.v4.app.Fragment;
     6 import android.support.v4.view.ViewPager;
     7 import android.support.v7.app.AppCompatActivity;
     9 import java.util.ArrayList;
    10 import java.util.List;
    12 
    13 public class MainActivity extends AppCompatActivity {
    14 
    15     @Override
    16     protected void onCreate(Bundle savedInstanceState) {
    17         super.onCreate(savedInstanceState);
    18         setContentView(R.layout.main_layout);
    19 
    21         TabLayout tabs = (TabLayout) this.findViewById(R.id.tabs);
    22 
    23         List<String> titles = new ArrayList<String>();
    24         List<Fragment> fragments = new ArrayList<Fragment>();
    25         for (int i=0; i<10; i++) {
    26             String title = "Tab"+ (i+1);
    27             tabs.addTab(tabs.newTab().setText(title));
    28             titles.add(title);
    29 
    30             Fragment fragment = new TestOneFragment(title);
    31             fragments.add(fragment);
    32         }
    33 
    34         ViewPager viewpager = (ViewPager) this.findViewById(R.id.viewpager);
    35         TestOneAdapter mAdapter = new TestOneAdapter(getSupportFragmentManager(), titles, fragments);
    36         viewpager.setAdapter(mAdapter);
    37         tabs.setupWithViewPager(viewpager);
    38         tabs.setTabsFromPagerAdapter(mAdapter);
    39 
    40         // 控制侧滑菜单的显示和隐藏
    41         //DrawerLayout drawer_layout = (DrawerLayout) this.findViewById(R.id.drawer_layout);
    42         //drawer_layout.closeDrawer();
    43     }
    44 
    45 }
  • 相关阅读:
    程序员的自我修养 符号修饰 函数签名 以及一个引申的问题: extern "c"
    Spring.NET学习笔记(1)基本依赖注入
    Spring.NET学习笔记(3)注册事件注入
    Spring.NET学习笔记(2)依赖注入细节
    jQuery LigerUI 使用教程入门篇
    Spring.NET学习笔记(5)对象生命周期和创建者对象
    【C#.NET】C#皮肤与主题应用实例
    【VB/C#】Kill进程
    【C#.NET】C#用户控件的使用
    【C#.NET】C#创建多语言网站
  • 原文地址:https://www.cnblogs.com/androidsj/p/4998025.html
Copyright © 2011-2022 走看看