Android Drawable 不符合其布局 match_parent
Android Drawable doesn't match_parent to it's layout
我正在用 drawable
设置 RelativeLayout
的背景,这是第一次打开 activity 时的 correct result。
但是,当我切换到另一个 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>
我正在用 drawable
设置 RelativeLayout
的背景,这是第一次打开 activity 时的 correct result。
但是,当我切换到另一个 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>