Comments (4)
版本:clone下来master运行和直接下载的Release v1.2.2中的mall_release.apk 描述:HomeFragment中addView(adView)未生效,即首页没有adView
binding.collapsableContent.run {
removeAllViews()
addView(banner)
addView(adView)
//这一行没有生效,即跑起来之后首页没有adViewaddView(nineMenuView)
}
什么机型,手上Android模拟器、华为meta10鸿蒙2.+ 正常
from jd_mall.
首先感谢作者抽空回复~
这边试过了几个测试机华为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.
@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.
感谢作者~
没足够仔细阅读代码 ==||
from jd_mall.
Related Issues (6)
- 怎么在viewmodle里面显示toast呢 HOT 2
- 商品规格 HOT 1
- category商品列表中的数据如何组装? HOT 1
- 一点建议 HOT 2
- React-Native模块配置问题求教 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jd_mall.