如何显示s.th。在android的列表下?

如何显示s.th。在android的列表下?,android,Android,我有一个广告,我想显示在我的名单下。目前,它已经超出了列表,并且可以正常工作。代码如下所示: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent"

我有一个广告,我想显示在我的名单下。目前,它已经超出了列表,并且可以正常工作。代码如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >  

    <fragment android:name="xx.AdFragment"
              android:id="@+id/ad_fragment"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" />

    <ExpandableListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ExpandableListView>


</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >  

    <ExpandableListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ExpandableListView>

    <fragment android:name="xx.AdFragment"
              android:id="@+id/ad_fragment"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" />
</LinearLayout>

问题是什么?

我认为在java代码中,您试图将FrameLayout强制转换为ExpandableListView

也许是这样的

ExpandableListView el = (ExpandableListView)findViewById(R.id.LinearLayout1);

尽管我在xml中没有看到任何框架布局。

您的方法将不起作用,因为您有一个线性布局。当ExpandableListView占据父视图的整个高度(您的线性布局)时,您的广告将退出屏幕。所以最好使用RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <fragment
        android:id="@+id/ad_fragment"
        android:name="xx.AdFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />

    <ExpandableListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/ad_fragment" >

    </ExpandableListView>

</RelativeLayout>

不客气,如果您觉得有用,您可以接受+投票:)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <fragment
        android:id="@+id/ad_fragment"
        android:name="xx.AdFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />

    <ExpandableListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/ad_fragment" >

    </ExpandableListView>

</RelativeLayout>