gpt4 book ai didi

Android Drawable 与它的布局不 match_parent

转载 作者:行者123 更新时间:2023-11-29 00:06:42 25 4
gpt4 key购买 nike

我正在使用 drawable 设置 RelativeLayout 的背景,这里是 correct result第一次打开 Activity 时。

但是,当我切换到另一个 Activity (具有相同背景)并返回到旧 Activity 时,背景正在缩放到它的可绘制大小 which is wrong .

或者有时,它在其他 Activity 中也一样(尺寸错误)。这是我用于布局根元素的常见 XML 布局:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/backgroundLayForBg"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- custom childs -->

</RelativeLayout>

什么会导致这个问题?

编辑:如果我设置背景颜色,我不会遇到任何问题。

最佳答案

使用这种方法:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- set background of activity using ImageView -->

<ImageView
android:id="@+id/mainBg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:scaleType="centerCrop" />

<!-- custom childs -->

</RelativeLayout>

关于Android Drawable 与它的布局不 match_parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33289227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com