我想改变我Listview的位于我的宽度和高度DrawerLayout:
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
DrawerLayout.LayoutParams myParam = new DrawerLayout.LayoutParams(20, 20);
mDrawerList.setLayoutParams(myParam);
但我得到这个错误:
06-21 09:30:57.361: E/AndroidRuntime(12583): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jk.demo/com.jk.demo.MemoStart}:
  java.lang.IllegalArgumentException: View android.widget.ListView{414506a8 VFED.VC. ......I. 0,0-0,0 #7f04003a app:id/left_drawer} is not a sliding drawer
drawer_main.xml
<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/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<ListView
    android:id="@+id/left_drawer"
    android:layout_width="540dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#111"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp" />
我导入:
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.LayoutParams;
有解决方案吗
根据Google指南,建议您DrawerLayout仅在安装并打开应用程序后首次打开(向用户显示该功能).
你会怎么做呢?
它似乎是一种openDrawer()方法与某种偏好的组合.
我想在我的Android项目中有一个NavigationDrawer,它始终部分显示ListView,并且项目也是可点击的,但是当用户拖动抽屉时,会显示完整的ListView.
下面的图像是我想要实现的:

第一个是"普通视图",您可以在其中看到小图标.第二个是当用户滑动导航抽屉以使其打开时.第三个是当回到普通视图中时,用户单击A和C,以便图标改变其颜色.
有什么建议怎么做?
谢谢回答 :)
android android-listview baseadapter navigation-drawer drawerlayout
我设计了一个抽屉布局,其中包含列表中的一些选项(基本上是菜单名称和图标).但我无法在抽屉布局的垂直中心制作列表视图.这是我的总xml布局:
 <?xml version="1.0" encoding="utf-8"?>
<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" >
    <!-- The main content view -->
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <include
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            layout="@layout/header" />
        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/linearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:background="@drawable/pink_header"
            android:orientation="horizontal"
            android:padding="5dip" >
            <TextView
                android:id="@+id/tot_detail_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="Talk of Town Details"
                android:textColor="#222222"
                android:textSize="14sp"
                android:textStyle="bold"
                android:typeface="sans" />
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_toRightOf="@id/feature_detail_title"
                android:gravity="right"
                android:orientation="horizontal" >
                <Button
                    android:id="@+id/drawer_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/ic_drawer"
                    android:visibility="visible" />
            </LinearLayout>
        </RelativeLayout>
        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
                <TextView
                    android:id="@+id/tot_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" …我的问题很简单.我可以在DrawerLayout的内容菜单中使用HorizontalScrollView吗?我的DrawerLayout看起来像这样:
<android.support.v4.widget.DrawerLayout
    android:id="@+id/pnlMenu"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <!-- Main content view -->
    <ListView
        android:id="@+id/lst"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:fastScrollEnabled="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        tools:listitem="@layout/item_layout" >
    </ListView>
    <!-- Content of menu -->
    <FrameLayout
        android:id="@+id/drawerFrame"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:clickable="true"
        android:background="@color/black" >
        <fragment
            android:id="@+id/frag"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.test.TestFragment" />
    </FrameLayout>
</android.support.v4.widget.DrawerLayout>
在片段内部我有HorizontalScrollView但是当我尝试触摸它时没有任何事情发生,因为抽屉布局跟随我的手指.我认为禁用内容菜单中的触摸事件并仅在单击主内容视图时使DrawerLayout可关闭将解决我的问题.真的吗?如果没有,有人可以告诉我,我该怎么办?
谢谢.
我一直在使用API 14开发应用程序,但我不得不降级到API 10.应用程序有片段和活动片段,我已经导入了库并使用了getFragmentSupportManager它,因为它是v4.但是,我有以下错误:

我从头开始创建了一个带有Drawer布局和API 10的虚拟应用程序,它在MyActivity文件中有相同的行,并且不是错误.这是我的代码:
package az.test2;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.Gravity;
public class MyActivity extends ActionBarActivity
    implements NavigationDrawerFragment.NavigationDrawerCallbacks {
    /**
     * Fragment managing the behaviors, interactions and presentation of the navigation drawer.
     */
    private NavigationDrawerFragment mNavigationDrawerFragment;
    /**
     * Used to store the last screen title. For use in {@link #restoreActionBar()}.
     */
    private CharSequence mTitle; …我的应用程序中有DrawerLayout两个抽屉,一个在左侧用于导航,另一个在右侧用于通知.当应用程序进行冷启动并向左滑动抽屉打开时,右侧抽屉从屏幕的最左侧跳到右侧.
它看起来像这样:http://i.imgur.com/mhoJ7MZ.gifv
如视频中所示,我尝试使用DrawerLayout's isDrawerOpen和isDrawerVisible方法试图看看它是否真的认为正确的抽屉是打开的(当它左边的抽屉打开时似乎"关闭"抽屉),但是我没有得到任何有用的东西.
是什么导致奇怪的跳跃?
我的活动的XML在下面,完整的代码在这里.
<?xml version="1.0" encoding="utf-8"?>
<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"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        ...
    </LinearLayout>
    <LinearLayout
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#ACFF0000"
        android:gravity="center"
        android:visibility="gone">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="LEFT DRAWER"
            android:textSize="24sp" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/right_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:background="#AC00FF00"
        android:gravity="center"
        android:visibility="gone">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RIGHT DRAWER"
            android:textSize="24sp" />
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>
这两种布局都可以在appcompat支持库7中找到.
我没有得到适当的结果.
我将DrawerLayout作为根布局,然后在其中包含一个错误文本视图.然后是SwipeRefreshLayout
当根布局为FrameLayout时,该textview是可见的.但自从我将根布局更改为DrawerLayout后,可能会出现错误textview从未显示!
我正确使用它吗?
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    tools:context="com.timesbuzz.news.MainActivity"
    android:id="@+id/drawer_layout">
    <TextView
        android:id="@+id/errorView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:text="@string/error_view_text"
        android:textSize="30sp" />
    <ProgressBar
        android:id="@+id/loadingView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:indeterminate="true" />
    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/contentView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- android.support.v4.view.ViewPager -->
        <fr.castorflex.android.verticalviewpager.VerticalViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v4.widget.SwipeRefreshLayout>
    <!-- The navigation drawer -->
    <ListView
        android:id="@+id/navdrawer"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:drawSelectorOnTop="false">
    </ListView>
</android.support.v4.widget.DrawerLayout>
android android-layout navigation-drawer drawerlayout swiperefreshlayout
每当我最初创建我的活动时,一切都很顺利,因为我能够正确地扩充我的布局.然而,问题是每当我切换到使用另一个应用程序,然后回到我自己的应用程序,我收到一个错误,说明TabLayout为空,导致我的应用程序崩溃.如果我切换到另一个应用程序几分钟,我DrawerLayout是空的,也导致我的应用程序崩溃.
如果我正确理解了Android生命周期,我意识到当活动从背景到前景时,活动会被重新创建,并且onCreate从这里引用该方法再次被调用:Android活动生命周期 - 这些方法的所有内容是什么?.但是,我不明白为什么当应用程序启动时,一切正常,但是当我进入后台时,或者将TabLayout其DrawerLayout设置为null.这是我的尝试:
news_feed.java:
private static DrawerLayout drawer;
private static TabLayout tabLayout;
public class news_feed extends BatchAppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.news_feed);
        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        //Listen for navigation events
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close){
        public void onDrawerOpened(View view) {
            super.onDrawerOpened(view);
        }
        /** Called when a drawer has settled in a …我知道我可以colorPrimary用来确定颜色Toolbar,并colorPrimaryDark确定状态栏的颜色.
我正在使用以下主题
<!-- Base application theme. -->
<style name="Theme.Noteplus.Base.Brown" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimaryLight</item>
    <item name="colorPrimaryDark">#ff0000</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>

其中一个有趣的属性是,当我滑出导航菜单时,状态栏会自动变为透明状态.

在运行期间,有时我想更改状态栏的颜色.
setTitle("Recycler bin");
toolbar.setBackgroundColor(Color.BLUE);
getWindow().setStatusBarColor(Color.parseColor("#5694FF"));
它看起来如下

不幸的是,setStatusBarColor当我们滑出导航菜单时,调用也会丢失状态栏的透明度属性.

我可以知道,如何在运行时更改状态栏颜色,而不会损失其透明属性?对于我的情况,在运行期间将状态栏更改为蓝色后,当我滑出导航抽屉时,我希望看到状态栏透明度属性被保留.
我试过了
private void setStatusBarColor(int color) {
    if (Build.VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(color);
    }
}
导航抽屉滑出时,提供透明属性无效.

android android-layout android-view drawerlayout windowinsets
android ×10
drawerlayout ×10
android-view ×1
baseadapter ×1
java ×1
layoutparams ×1
listview ×1
touch-event ×1
windowinsets ×1