android内置测拉栏DrawerLayout的使用
来源:互联网 发布:淘宝客服礼貌用语 编辑:程序博客网 时间:2024/05/18 22:42
第一步导库配置
这个空间是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;@Overrideprotected 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
- android内置测拉栏DrawerLayout的使用
- Android - DrawerLayout的使用
- Android DrawerLayout的使用
- Android DrawerLayout的使用
- Android DrawerLayout的使用
- Android DrawerLayout的使用
- android的DrawerLayout使用
- android抽屉DrawerLayout的使用
- Android下DrawerLayout的使用
- Android侧滑菜单DrawerLayout的使用
- Android中DrawerLayout控件的使用
- Android中使用DrawerLayout的注意点
- Android控件之Toolbar + DrawerLayout的使用
- android 官方DrawerLayout的介绍和使用
- 【Android - V】之DrawerLayout的使用
- Android 控件DrawerLayout的基本使用
- Android开发之DrawerLayout的简单使用
- android DrawerLayout 抽屉布局的使用
- 类加载器和双亲委托机制
- Java设计模式----代理模式
- 打破思考的定式:
- Codeforces 749C【模拟】
- Java 生产者消费者 多线程 toys
- android内置测拉栏DrawerLayout的使用
- c++基础
- OpenGL环境配置
- 【Android】可移动的ImageView
- 数据源配置
- LintCode41:最大子数组
- 机器学习中的偏差(bias)和方差(variance)
- 产品被批,随便写俩字
- 安卓实体类implements Serializable的意图作用