如何在android kotlin中每27个用户加载图像后设置adview

How to set adview after every 27 users of image loading in android kotlin

提问人:chanthini begam 提问时间:6/10/2023 最后编辑:chanthini begam 更新时间:6/10/2023 访问量:14

问:

如何设置每加载 27 组用户图片后的 adview。每组图像(27个用户)加载后,必须将小广告显示到嵌套的滚动视图中。Kotlin 代码和 adview xml 如下所示:

    private fun loadNext27(peoples: List<PeopleNearByModelClass>) {

    try {

        coroutineScope.launch(Dispatchers.IO) {

            minPeopleCount =
                peopleNearbyFirstRow.size + peopleNearbySecondRow.size + peopleNearbyThirdRow.size
            val maxPeopleCount = peoples.size.coerceAtMost(minPeopleCount!! + 27)

            minPeopleCountDummy = maxPeopleCount

            peopleNearbyFirstRowList = ArrayList()
            peopleNearbySecondRowList = ArrayList()
            peopleNearbyThirdRowList = ArrayList()

            var i: Int = minPeopleCount as Int
            try {
                while (i < maxPeopleCount) {
                    i += 3
                    peopleNearbyFirstRowList.add(peoples[i])
                    peopleNearbySecondRowList.add(peoples[i + 1])
                    peopleNearbyThirdRowList.add(peoples[i + 2])

                    peopleNearbyFirstRow.add(peoples[i])
                    peopleNearbySecondRow.add(peoples[i + 1])
                    peopleNearbyThirdRow.add(peoples[i + 2])
                }
            } catch (e: Exception) {
                e.printStackTrace()
            }
            loadNext27UI(
                peopleNearbyFirstRowList,
                peopleNearbySecondRowList,
                peopleNearbyThirdRowList, peoples.size
            )
        }

    } catch (e: Exception) {
        e.printStackTrace()
    }
}

我想将此 adview 代码设置到此方法中。

private fun showAd() {

}

以下代码是我要将 AdView 添加到嵌套滚动视图中的 XML 代码:

  <LinearLayout
        android:id="@+id/containerPeopleNearby"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:visibility="visible"
        android:layout_weight="1"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.core.widget.NestedScrollView
            android:id="@+id/peopleNearbyNestedScroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:paddingBottom="36dp"
            android:layout_margin="0dp"
            android:scrollbars="none">
            <LinearLayout
                android:id="@+id/linearLayoutDynamic"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal"
                android:baselineAligned="false"
                android:orientation="horizontal"
                tools:ignore="UnusedAttribute">
                <LinearLayout
                    android:id="@+id/peopleNearbyMainLay1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:clipToPadding="false"
                    android:nestedScrollingEnabled="false"
                    android:orientation="vertical"
                    android:overScrollMode="never"
                    android:paddingTop="40dp"
                    android:scrollbars="none"
                    tools:listitem="@layout/list_item_right_adapter" />
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="vertical">
                    <com.google.android.material.card.MaterialCardView
                        android:id="@+id/people_nearby_user_image_layout"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:layout_centerInParent="false"
                        android:layout_centerHorizontal="true"
                        android:layout_gravity="center_horizontal"
                        android:layout_marginTop="5dp"
                        android:visibility="gone"
                        app:cardCornerRadius="25dp"
                        app:cardElevation="8dp">

                        <com.google.android.material.imageview.ShapeableImageView
                            android:id="@+id/people_nearby_user_image"
                            android:layout_width="50dp"
                            android:layout_height="50dp"
                            android:layout_gravity="center"
                            android:layout_marginStart="8dp"
                            android:layout_marginTop="8dp"
                            android:layout_marginEnd="8dp"
                            android:layout_marginBottom="8dp"
                            android:scaleType="fitXY"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent"
                            tools:ignore="ContentDescription"/>

                    </com.google.android.material.card.MaterialCardView>

                    <LinearLayout
                        android:id="@+id/peopleNearbyMainLay2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:clipToPadding="false"
                        android:nestedScrollingEnabled="false"
                        android:orientation="vertical"
                        android:overScrollMode="never"
                        android:paddingTop="95dp"
                        android:scrollbars="none"
                        tools:listitem="@layout/list_item_right_adapter"/>

                </RelativeLayout>

                <LinearLayout
                    android:id="@+id/peopleNearbyMainLay3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:clipToPadding="false"
                    android:nestedScrollingEnabled="false"
                    android:orientation="vertical"
                    android:overScrollMode="never"
                    android:paddingTop="40dp"
                    android:scrollbars="none"
                    tools:listitem="@layout/list_item_right_adapter" />


                <androidx.constraintlayout.widget.ConstraintLayout
                    android:id="@+id/ad_lay"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/linearLayoutDynamic"

                    android:layout_gravity="center|bottom"
                    android:layout_marginBottom="10dp"
                    android:gravity="center"
                    android:orientation="horizontal"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/linearLayoutDynamic"
                    app:layout_constraintVertical_bias="1.0"
                    app:layout_constraintVertical_chainStyle="spread_inside">


            </LinearLayout>


        </androidx.core.widget.NestedScrollView>


    </LinearLayout>
Android 列表 Kotlin 设置 AdView

评论


答: 暂无答案