0

下面是我在 .xml 中动态膨胀的 xml Fragment。但是,当我这样做时,

NativeAppInstallAdView add = (NativeAppInstallAdView) contentView.findViewById(R.id.adView);

在其他视图喜欢的地方,add参考将变为空

ImageView imgLogo = (ImageView) contentView.findViewById(R.id.ivLogo);

工作正常。我无法确切知道为什么会在这里发生。任何帮助都会很棒。

<com.google.android.gms.ads.formats.NativeAppInstallAdView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/linearAdView"
        android:layout_width="match_parent"
        android:focusable="true"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tvHeader"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/ivLogo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/tvDescription"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="1dp">

                    <TextView
                        android:id="@+id/tvStore"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true" />

                    <TextView
                        android:id="@+id/tvPrice"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true" />
                </RelativeLayout>

            </LinearLayout>
        </LinearLayout>

        <ImageView
            android:id="@+id/ivImage"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="2dp"
            android:background="#00FFFFFF"
            android:scaleType="center" />

        <Button
            android:id="@+id/btnAction"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp" />
    </LinearLayout>

</com.google.android.gms.ads.formats.NativeAppInstallAdView>
4

0 回答 0