ClassCastException android.widget.FrameLayout$LayoutParams to android.support.v4.widget.DrawerLayout$LayoutParams

五迷三道 提交于 2019-11-27 12:35:32
Armaan Stranger

Answer:

mDrawerLayout.closeDrawer(mDrawerLayout);

had wrong Layout. so change in it with drawerlayout will work it out.

Jonik

What solved this issue for me:

In MainActivity, add a new field for the LinearLayout, and assign value to it in onCreate() (this part just like emaleavil suggested):

private LinearLayout linearLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // ...
    linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
}

Then in selectItem(), when calling closeDrawer(), simply pass linearLayout as argument:

drawerLayout.closeDrawer(linearLayout);

I had the same problem. I just got rid of using,

mDrawerLayout.closeDrawer(Gravity.LEFT);

I had the same issue... Solution in my case was:

In your MainActivity add:

private LinearLayout linearLayout;

public void onCreate(Bundle savedInstanceState){

    ...
linearLayout = (LinearLayout)findViewById(R.id.linearLayout);
    ...

}

OnPrepareOptionsMenu:

@Override
        public boolean onPrepareOptionsMenu(Menu menu) {
            boolean drawerOpen = mDrawerLayout.isDrawerOpen(this.linearLayout);
            menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
            return super.onPrepareOptionsMenu(menu);
}

I'm sorry for my poor english.

I think you should place your content and drawer exactly as it is siad in the manual. Now yor XML structure doesn't match that. Note, that only the "id" field should match, the view types and parameters may be different.

finally I found the way to implement a custom listView in the drawer layout. This is the post that help me to do it...http://www.michenux.net/android-navigation-drawer-748.html

mDrawerLayout.closeDrawer(mDrawerLayout);

or

mDrawerLayout.closeDrawer(Gravity.LEFT);

both is ok.NOTE:you must know What is parameter.

Have a nice day !

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!