Pregunta

I've got a DrawerLayout in my Android app, it works perfectly fine, but it doesn't do what I want it to do. I want to implement a DrawerLayout that's always "opened" or peeking, so it can show the icons of menu items, and it can slide open all the way to show the full listview of the menu (so icon + menu text). Is this possible?

This is my class and xml now:

public class MainActivity extends Activity {

private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle("App title");
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle("Menu");
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    } else {
        return false;
    }
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    // Pass any configuration change to the drawer toggls
    mDrawerToggle.onConfigurationChanged(newConfig);
}

}

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" >

</FrameLayout>

<RelativeLayout
    android:id="@+id/left_drawer"
    android:layout_width="80dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#eee" >

    <ListView
        android:id="@+id/drawerMenu"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>

I'll implement the menu later, I just need to know how to keep the DrawerLayout in a persisting "peek-a-boo" mode.

¿Fue útil?

Solución

I finally came across the information to do this. You can use a different kind of layout for it. Instead of DrawerLayout, you can use SlidingPaneLayout.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top