0

リストの下に表示したい広告があります。現在、それはリストを超えており、機能しています。コードは次のようになります。

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

アプリがクラッシュし、次のエラーが表示されます。

10-29 12:35:56.288: E/AndroidRuntime(13712): FATAL EXCEPTION: main
10-29 12:35:56.288: E/AndroidRuntime(13712): java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx/xxx.MainActivity}: java.lang.ClassCastException: android.support.v4.app.NoSaveStateFrameLayout cannot be cast to android.widget.ExpandableListView

何が問題ですか?

4

2 に答える 2

1

あなたのJavaコードでは、FrameLayoutをExpandableListViewにキャストしようとしていると思います。

たぶん、このようなもの

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

あなたのxmlにFrameLayoutは表示されませんが。

于 2013-10-29T11:41:09.977 に答える
0

線形レイアウトがあるため、このアプローチは機能しません。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>
于 2013-10-29T12:08:03.660 に答える