Git Product home page Git Product logo

Comments (4)

GuoguoDad avatar GuoguoDad commented on July 2, 2024

版本:clone下来master运行和直接下载的Release v1.2.2中的mall_release.apk 描述:HomeFragment中addView(adView)未生效,即首页没有adView binding.collapsableContent.run { removeAllViews() addView(banner) addView(adView) //这一行没有生效,即跑起来之后首页没有adView addView(nineMenuView) }

什么机型,手上Android模拟器、华为meta10鸿蒙2.+ 正常

from jd_mall.

heluicare avatar heluicare commented on July 2, 2024

首先感谢作者抽空回复~

这边试过了几个测试机华为Meta10 Pro(EMUI 10.0.0、Android 10)、华为P10(EMUI 8.0.0 Android 8)、vivo X23(Funtouch OS_10 Android 9)结果都是一样,不显示adView。

另外把 home_ad.xml 修改如下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="300dp"
    android:background="@color/colorAccent"
    android:layout_height="100dp">

    <ImageView
        android:id="@+id/adImg"
        android:background="@color/purple_200"
        android:layout_width="150dp"
        android:layout_height="100dp"
        android:scaleType="fitXY" />

</RelativeLayout>

把 HomeFragment 修改如下

binding.collapsableContent.run {
            removeAllViews()
            addView(banner)
            adView.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, 300)
            addView(adView)
            addView(nineMenuView)
        }

adView也没有显示出相应的背景色,只有一个高度为300的空白区域。

而如果修改如下:

binding.collapsableContent.run {
            removeAllViews()
            addView(banner)
            adView.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, 300)
            adView.setBackgroundResource(R.color.indicator_selected_color)
            addView(adView)
            addView(nineMenuView)
        }

页面上则有一个高度为300的绿色区域。

还有如果修改如下:

binding.collapsableContent.run {
            removeAllViews()
            addView(banner)
            var img: ImageView = ImageView(context)
            img.setImageResource(R.drawable.default_img)
            addView(img)
            addView(nineMenuView)
        }

此时页面可以显示img

所以貌似是通过添加布局文件的方式然后不知什么原因导致adView的Measure失效了?

from jd_mall.

GuoguoDad avatar GuoguoDad commented on July 2, 2024

@heluicare 已修复,原因少了2参数

`class AdView(context: Context): FrameLayout(context) {
private var binding: HomeAdBinding
private var imageLoader: ImageLoader = CoilUtil.getImageLoader()
init {
binding = HomeAdBinding.inflate(LayoutInflater.from(context), this, true)
}

fun setData(url: String) {
    binding.adImg.load(url, imageLoader ) {
        crossfade(true)
        placeholder(R.drawable.default_img)
        error(R.drawable.default_img)
    }
}

}`

from jd_mall.

heluicare avatar heluicare commented on July 2, 2024

感谢作者~

没足够仔细阅读代码 ==||

from jd_mall.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.