我已就此主题进行了大量搜索.我做了以下事情:
我已经将支持库用于另一个项目,它工作正常,但我没有使用drawerlayout.下面是我在活动类中调用的xml文件.它调用时会发生此错误setContentView(R.layout.main_sliding_layout);
<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/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:background="@color/list_background"/>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud) 我正在关注帖子"Android设计库NavigationView with footer",在NavigationView底部添加按钮.问题是只出现最后一个NavigationView,它占据整个屏幕高度.
这是我的布局:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Activity here -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<android.support.design.widget.NavigationView
android:id="@+id/navigation_menu_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="top"
app:menu="@menu/menu_drawer"/>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_footer_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:menu="@menu/menu_drawer_footer"/>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
结果如下:
我怎样才能解决这个问题?
public DrawerProfile(Context context) {
super(context);
HeaderImageView = new ImageView(context);
HeaderImageView.setVisibility(VISIBLE);
HeaderImageView.setScaleType(ImageView.ScaleType.CENTER);
HeaderImageView.setImageResource(R.mipmap.drawer_background_image);
addView(HeaderImageView);
}
Run Code Online (Sandbox Code Playgroud)
我想在Drawer中添加一个图像,它应该覆盖抽屉头的整个区域.我想知道图像(分辨率)的大小应该是多少; 适用于各种屏幕分辨率的手机.如何最小化照片尺寸?
在此屏幕截图中,标题图像未覆盖Drawer的整个区域
android android-layout image-size navigation-drawer drawerlayout
我在DrawerLayout组件中遇到了一些问题.我正在使用android-support-v4 jar,当我启动应用程序时,我有以下异常:
05-19 01:33:57.402: E/AndroidRuntime(3120): FATAL EXCEPTION: main
05-19 01:33:57.402: E/AndroidRuntime(3120): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dimosphere.app/com.dimosphere.app.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.v4.widget.DrawerLayout
05-19 01:33:57.402: E/AndroidRuntime(3120): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
05-19 01:33:57.402: E/AndroidRuntime(3120): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
05-19 01:33:57.402: E/AndroidRuntime(3120): at android.app.ActivityThread.access$600(ActivityThread.java:153)
05-19 01:33:57.402: E/AndroidRuntime(3120): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
05-19 01:33:57.402: E/AndroidRuntime(3120): at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 01:33:57.402: E/AndroidRuntime(3120): at android.os.Looper.loop(Looper.java:137)
05-19 01:33:57.402: E/AndroidRuntime(3120): at android.app.ActivityThread.main(ActivityThread.java:5226)
05-19 01:33:57.402: E/AndroidRuntime(3120): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 01:33:57.402: E/AndroidRuntime(3120): at java.lang.reflect.Method.invoke(Method.java:511)
05-19 01:33:57.402: E/AndroidRuntime(3120): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-19 01:33:57.402: …Run Code Online (Sandbox Code Playgroud) android android-support-library navigation-drawer drawerlayout
在Android中使用DrawerLayout时,打开抽屉会导致主要内容区域变暗.是否有任何方法可以避免这种情况,以便在抽屉出来时主要内容保持同样可见?
谷歌推出了DrawerLayout,当你点击动作栏的"向上"按钮时,它会在屏幕的左侧区域显示一个菜单.
因为在actionBarSherlock上还不支持库,所以已经有办法使用这个项目来克服它.
它已经在许多应用程序上有变种:潮流,gmail,环聊,youtube ......
在"电流"应用程序(和youtube)中,当用户从左向右滑动(最左侧)页面时,无论手指在哪里开始触摸,都会出现DrawerLayout .
我怎样才能达到同样的效果?也许我应该使用onInterceptTouchEvent ?
除了这个链接之外,没有太多关于可以做什么很酷的文档和教程(好的,也是这个).他们说(在"给用户快速查看"部分)左边大约20dp用于此功能,但我可以看到"电流"工作的区域更大.
看来这个库还没有完成,所以布局xml文件甚至无法在可视UI编辑器中显示...
编辑:似乎该库是开源的.代码可用于:
.../android-sdk\sources\android-18\android\support\v4\widget\DrawerLayout.java
.../android-sdk\sources\android-18\android\support\v4\widget\SlidingPaneLayout.java
.../android-sdk\sources\android-18\android\support\v4\app\ActionBarDrawerToggle.java
Run Code Online (Sandbox Code Playgroud)
现在的问题是如何让它像我写的那样工作,这样它就可以在youtube上工作,允许我们自定义它的外观和从哪里滚动它.
我正在Android Studio中设计原生导航抽屉.我在预览中看不到抽屉,因为它位于活动的左侧,超出预览范围.现在我正在使用testlayout.xml文件来查看我的更改,但很多时候我忘记将它们复制粘贴到正确的活动中.有没有办法预览抽屉布局?
android preview android-studio navigation-drawer drawerlayout
我有一个抽屉式导航栏中像这样.
我想要做的是打开我的抽屉全屏而不是半屏.如何将此抽屉打开为全屏?
这是xml of drawerlayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include
android:id="@+id/toolbar_layout"
layout="@layout/app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar_layout"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<FrameLayout
android:id="@+id/activityMainContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/colorPrimary"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:itemTextColor="@android:color/white"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)