android 我想在相对布局中添加透明黑色背景图像

o75abkj4  于 2023-06-27  发布在  Android
关注(0)|答案(1)|浏览(180)

image i want但是在实现它的时候它会变成这样enter image description here如何修复layout_height

  1. <RelativeLayout
  2. android:id="@+id/rel_top"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content">
  5. <LinearLayout
  6. android:id="@+id/lin_detail"
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content"
  9. android:background="@color/blackTrans80"
  10. android:orientation="horizontal">
  11. ...
  12. </LinearLayout>
  13. </RelativeLayout>
  1. val relativeLayout = findViewById<RelativeLayout>(R.id.rel_top)
  2. val thumbnailUrl = comicDetailAPI!!.data.comic_detail.thumbnail
  3. setRelativeLayoutBackgroundWithThumbnail(relativeLayout, thumbnailUrl)
  1. fun setRelativeLayoutBackgroundWithThumbnail(relativeLayout: RelativeLayout, thumbnailUrl: String) {
  2. val requestOptions = RequestOptions().centerCrop()
  3. Glide.with(relativeLayout)
  4. .load(thumbnailUrl)
  5. .apply(requestOptions)
  6. .into(object : SimpleTarget<Drawable>() {
  7. override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
  8. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
  9. relativeLayout.background = resource
  10. }
  11. }
  12. })
  13. }

如何在相对布局中固定layout_height

hof1towb

hof1towb1#

将布局高度更改为Odp。

  1. <RelativeLayout
  2. android:id="@+id/rel_top"
  3. android:layout_width="match_parent"
  4. android:layout_height="0dp">
  5. <LinearLayout
  6. android:id="@+id/lin_detail"
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content"
  9. android:background="@color/blackTrans80"
  10. android:orientation="horizontal">
  11. ...
  12. </LinearLayout>
  13. </RelativeLayout>

如果0dp在RelativeLayout中不起作用,则保留相对布局高度(“wrap_content”)。并尝试更改LinearLayout高度0dp。它将涵盖您在XML中声明的完整视图。

  1. <RelativeLayout
  2. android:id="@+id/rel_top"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content">
  5. <LinearLayout
  6. android:id="@+id/lin_detail"
  7. android:layout_width="match_parent"
  8. android:layout_height="0dp"
  9. android:background="@color/blackTrans80"
  10. android:orientation="horizontal">
  11. ...
  12. </LinearLayout>
  13. </RelativeLayout>
展开查看全部

相关问题