Android 为什么我的应用程序在安卓系统的抽屉布局中添加Relativelayout后会强制关闭?

Android 为什么我的应用程序在安卓系统的抽屉布局中添加Relativelayout后会强制关闭?,android,listview,android-relativelayout,drawerlayout,Android,Listview,Android Relativelayout,Drawerlayout,我正在尝试为slider Listview获得阴影效果。我正试图在ListView下面放置一个与阴影图像相对的窗口。我已经在xml文件中执行了以下操作,但强制关闭时出现以下错误。请一步一步地指导我该做什么,我哪里做错了 我的xml文件 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout

我正在尝试为slider Listview获得阴影效果。我正试图在ListView下面放置一个与阴影图像相对的窗口。我已经在xml文件中执行了以下操作,但强制关闭时出现以下错误。请一步一步地指导我该做什么,我哪里做错了

我的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>


     <FrameLayout
        android:layout_width="250dp"
        android:layout_height="match_parent"
         > 

   <ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="#656565"
    android:dividerHeight="0.01dp"
     android:fadingEdgeLength="10dp"

    android:background="@color/list_background"
    android:listSelector="@drawable/list_selector"
   />

</FrameLayout>
   </android.support.v4.widget.DrawerLayout>
Profile.class

   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    final HashMap<String, String> c=db.getAddedContacts();
    // Initializing
    dataList = new ArrayList<DrawerItem>();
    mTitle = mDrawerTitle = getTitle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
     TypefaceSpan tp;
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
            GravityCompat.START);
          final ActionBar actionBar = getActionBar();

    actionBar.setBackgroundDrawable(getResources().getDrawable(R.color.green));
    actionBar.setCustomView(R.layout.actionbars);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setIcon(
              new ColorDrawable(getResources().getColor(android.R.color.transparent)));  
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
final HashMap c=db.getAddContacts();
//初始化
dataList=newarraylist();
mTitle=mDrawerTitle=getTitle();
mDrawerLayout=(抽屉布局)findViewById(R.id.抽屉布局);
mDrawerList=(ListView)findViewById(R.id.left\u抽屉);
字体跨度tp;
mDrawerLayout.setDrawerShadow(R.drawable.DrawerShadow,
重力比较(启动);
最终ActionBar ActionBar=getActionBar();
setBackgroundDrawable(getResources().getDrawable(R.color.green));
actionBar.setCustomView(R.layout.actionBar);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setIcon(
新的ColorDrawable(getResources().getColor(android.R.color.transparent));

显然,您的listView位于
FrameLayout
的内部。如果删除它,一切正常

否则,在xml中将id设置为
2nd
frameLayout

android:id="@+id/framelayout"
然后获取该
FrameLayout

FrameLayout frameLayout = (LinearLayout) findViewById(R.id.frameLayout);
FrameLayout
的实例传递给
mDrawerLayout.closeDrawer(FrameLayout);


希望这能解决问题。

Line
311
Profile.java
中。请在引用此布局的地方发布活动代码。根据这一点,除了告诉您,不可能将抽屉布局强制转换为相对布局,它会引发ClassCastException,因为它说您正在尝试这样做,我有没有在我的活动代码中的任何地方引用此布局。只是在xml文件中添加了错误在你的活动代码中。K然后我将添加我的活动代码
FrameLayout frameLayout = (LinearLayout) findViewById(R.id.frameLayout);