android内置测拉栏DrawerLayout的使用

第一步导库配置
这个空间是widget包下的一个控件加入依赖
compile ‘com.android.support:appcompat-v7:25.0.1’
第二步使用
首先在住布局main_activity.xml。

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/dl"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:id="@+id/activity_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            tools:context="org.cocos2d.ndkdemo.MainActivity">

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="testNdk" />
        </RelativeLayout>
        //end 表示滑动菜单栏在右边 ,start表示滑动测拉栏在左边
        <LinearLayout
            android:id="@+id/container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:orientation="vertical" />
    </android.support.v4.widget.DrawerLayout>

在代码中使用
首先右测拉栏内容,放置一个RightProductFragment

public class RightProductFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
TextView tv=new TextView(getActivity());
Bundle bundle= setArguments();
String product= bundle.getString(“product”);
tv.setText(product);
return tv;
}

public static RightProductFragment getInstance(String args) {
    RightProductFragment mProductFragment = new RightProductFragment();
    Bundle bundle = new Bundle();
    bundle.putString("product", args);
    mProductFragment.setArguments(bundle);
    return mProductFragment;
}

在MainActivity中的使用

public class MainActivity extends Activity {

private DrawerLayout drawerlayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    drawerlayout = (DrawerLayout) findViewById(R.id.dl);
    //禁止测拉栏通过手势滑动打开
   // drawerlayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    getFragmentManager().beginTransaction().replace(R.id.container, RightProductFragment.getInstance("hhahah")).commit();
}

public void testNdk(View view) {
//表示点击按钮开启测拉栏
    drawerlayout.openDrawer(Gravity.RIGHT);
}

}
“`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值