Bir ListView içeren özel bir DrawerLayout kullanmaya çalışıyorum ancak çalışamıyorum. Bunu daha özel hale getirebilmek ve ListView üzerinde bir Görüntü ekleyebilmek için LinearLayout'un içeriğini kaydırmadan önce çalışmayı başarabiliyordum.Çekmece KapatmaLayout istisna neden olur: LinearLayout, DrawerLayout'a dönüştürülemiyor
LineLayout'u taşırken CloseDrawer() öğesini kapatmaya çalıştığımda bu özel durum devam ediyor, ancak bu tür bir sorunla ilgili birden çok ileti görüyorum ancak bunların çoğu için düzeltme LinearLayout öğesini closeDrawer() işlevine iletmektir Ben zaten yaptım:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<include layout="@layout/action_bar" />
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/left_drawer_item"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical">
<ImageView
android:id="@+id/profilIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_people1blue2x" />
<ListView
android:id="@+id/left_drawer_child"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
: Burada
@Bind(R.id.drawer_layout)
DrawerLayout mDrawerLayout;
@Bind(R.id.actionToolbar)
Toolbar toolbar;
@Bind(R.id.left_drawer_item)
LinearLayout mDrawerLinear;
@Bind(R.id.left_drawer_child)
ListView mDrawerListChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_v2_home);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(getResources().getString(R.string.app_name));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mPlanTitles = getResources().getStringArray(R.array.plan_list);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener
ArrayList<String> myList = new ArrayList<>();
myList.add("First Item");
myList.add("Second Item");
mDrawerListChild.setAdapter(new DrawerListAdapter(this, R.layout.drawer_layout_item, myList));
mDrawerListChild.setOnItemClickListener(new DrawerItemClickListener());
// enable ActionBar app icon to behave as action to toggle nav drawer
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
toolbar, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
//syncActionBarArrowState();
}
public void onDrawerOpened(View drawerView) {
//mDrawerToggle.setDrawerIndicatorEnabled(true);
}
};
getSupportFragmentManager().addOnBackStackChangedListener(mOnBackStackChangedListener);
mDrawerLayout.setDrawerListener(mDrawerToggle);
setSupportActionBar(toolbar);
user = getUser();
if (savedInstanceState == null) {
selectItem(0);
}
}
private void selectItem(int position) {
BackHandledFragment fragment = new FragmentMobilePlan();
setSelectedFragment(fragment);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.pull_in_right, R.anim.push_out_left, R.anim.pull_in_left, R.anim.push_out_right);
ft.replace(R.id.content_frame, fragment)
.commit();
// update selected item and title, then close the drawer
mDrawerListChild.setItemChecked(position, true);
setTitle(mPlanTitles[position]);
mDrawerLayout.closeDrawer(mDrawerLinear);
}
benim düzenidir:
İşte
04-05 12:17:10.100 18879-18879/com.plante.android.cobalt E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.plante.android.cobalt, PID: 18879
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.plante.android.cobalt/com.plante.android.cobalt.activityv2.ActivityHome}: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
at android.support.v4.widget.DrawerLayout.isDrawerView(DrawerLayout.java:1415)
at android.support.v4.widget.DrawerLayout.closeDrawer(DrawerLayout.java:1630)
at com.plante.android.cobalt.activityv2.ActivityHome.selectItem(ActivityHome.java:190)
at com.plante.android.cobalt.activityv2.ActivityHome.onCreate(ActivityHome.java:155)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
benim faaliyettir
Olası yinelenen http://stackoverflow.com/questions/17939798/classcastexception-android-widget-framelayoutlayoutparams-to -android-support-v4) –
Çekmece xml'iniz nedir? –
@ Ben-J ekledim, – Jaythaking