仿QQUI实现(1)

DrawerLayout+FragmentTabHost

本节主要内容:

  • DrawerLayout简介
  • DrawerLayout使用
  • FragmentTabHost简介
  • 进行项目编码

1.DrawerLayout简介
DrawerLayout这个类位于android.support.v4.widget包下,要想在项目中使用它,必须在gradle文件中添加依赖,格式如下:

compile 'com.android.support:support-v4:23.0.1'

另外我在项目中使用了ButterKnife,有关于ButterKnife的详细信息参见官网ButterKnife官网,在项目中通过下面这句添加ButterKnife依赖:

compile 'com.jakewharton:butterknife:7.0.1'

由于项目后面会用到动画效果所以还要添加nineoldandroids依赖:

compile 'com.nineoldandroids:library:2.4.0'

完整的dependencies如下所示:


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.nineoldandroids:library:2.4.0'
}

2.DrawerLayout使用
在代码中通过引用com.android.support.v4.widget.DrawerLayout创建DrawerLayout,完整的实例如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/activity_main_menu_drawerlayout">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <RelativeLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <Button
                android:id="@+id/activity_main_open_right_menu"
                android:layout_alignParentRight="true"
                android:text="右边菜单"
                android:layout_marginRight="16dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </RelativeLayout>
    </RelativeLayout>

    <fragment
        android:id="@+id/activity_main_left_menu"
        android:name="类的完整名称"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="left"
        android:tag="LEFT">
    </fragment>

    <fragment
        android:id="@+id/activity_main_right_menu"
        android:name="类的完整名称"
        android:layout_width="20dp"
        android:layout_gravity="right"
        android:layout_height="fill_parent"
        android:tag="RIGHT"></fragment
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值