【问题标题】:Scale background image and foreground image at same ratio in Android在Android中以相同的比例缩放背景图像和前景图像
【发布时间】:2013-07-18 18:14:21
【问题描述】:

我有一个居中的背景图像,其中包含我使用 ImageView 显示的图案。我希望它填充所有不同屏幕尺寸/密度的宽度和高度,但保持其纵横比。我想我已经弄清楚了那部分,但是我有一个更小且居中的前景图像(在 ToggleButton 中),并且需要以与背景图像相同的速率进行缩放。这很重要,因为按钮图像具有需要与背景完美对齐的图形元素。如何让它正确缩放?到目前为止,这是我所得到的:

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

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="centerCrop"
    android:layout_centerInParent="true"
    android:contentDescription="@string/bg_desc"
    android:src="@drawable/bg_img" />

<ToggleButton
    android:id="@+id/button"
    android:background="@drawable/btn_on"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="center"
    android:layout_centerInParent="true"
    android:textOff=""
    android:textOn=""
    android:onClick="toggleLight" />

</RelativeLayout>

感谢观看!

【问题讨论】:

    标签: android background image-scaling foreground aspect-ratio


    【解决方案1】:

    按照我的技术,我觉得你应该这样做

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop"
    android:layout_centerInParent="true"
    android:contentDescription="@string/bg_desc"
    android:background="@drawable/bg_img" />
    

    可能会如你所愿。

    【讨论】:

      猜你喜欢
      • 2013-09-18
      • 1970-01-01
      • 2012-07-08
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多