【问题标题】:Android Drawable doesn't match_parent to it's layoutAndroid Drawable 与它的布局不匹配
【发布时间】:2015-10-22 19:33:38
【问题描述】:

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

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

或者有时,在其他活动中也是如此(大小错误)。这是我用于布局根元素的常见 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>

什么会导致这个问题?

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

【问题讨论】:

    标签: android android-layout drawable


    【解决方案1】:

    使用这种方法:

    <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>
    

    【讨论】:

      猜你喜欢
      • 2015-10-28
      • 2015-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      相关资源
      最近更新 更多