image i want但是在实现它的时候它会变成这样enter image description here如何修复layout_height
<RelativeLayout
android:id="@+id/rel_top"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/lin_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/blackTrans80"
android:orientation="horizontal">
...
</LinearLayout>
</RelativeLayout>
val relativeLayout = findViewById<RelativeLayout>(R.id.rel_top)
val thumbnailUrl = comicDetailAPI!!.data.comic_detail.thumbnail
setRelativeLayoutBackgroundWithThumbnail(relativeLayout, thumbnailUrl)
fun setRelativeLayoutBackgroundWithThumbnail(relativeLayout: RelativeLayout, thumbnailUrl: String) {
val requestOptions = RequestOptions().centerCrop()
Glide.with(relativeLayout)
.load(thumbnailUrl)
.apply(requestOptions)
.into(object : SimpleTarget<Drawable>() {
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
relativeLayout.background = resource
}
}
})
}
如何在相对布局中固定layout_height
1条答案
按热度按时间hof1towb1#
将布局高度更改为Odp。
如果0dp在RelativeLayout中不起作用,则保留相对布局高度(“wrap_content”)。并尝试更改LinearLayout高度0dp。它将涵盖您在XML中声明的完整视图。