2

我想在我的活动背景中放置一张图片。该图像实际上是一个圆形徽标,它将是半透明的,并且应该位于 UI 上任何其他内容的后面。我还将把它偏移到底角。

在不同的屏幕尺寸下,我可以放置此图像而不会“压扁”(蛋形)的最佳方法是什么?我的应用程序将仅在纵向模式下运行。

这就是我想要实现的目标:

在此处输入图像描述

到目前为止,我已经将我的圆形图像放置在 3 个用于流行尺寸屏幕的白色矩形画布上,480x854这似乎可行,但我认为它不是很牢固。320x480240x320

有小费吗?

4

2 回答 2

1

这可能不是完美的解决方案,并且需要对 UI 进行一些维护,但这是我的想法:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginRight="-15dp"
        android:layout_marginBottom="-15dp"
        android:src="@drawable/circle"
        />
    <!--Rest of Layout goes here-->
</FrameLayout>

只需将其包裹在您当前的布局中,然后将右边距和底部边距调整为您希望偏移的任何负边距。这应该适用于任何屏幕尺寸,假设您有每个密度的可绘制对象。

编辑:是的,你也不应该担心这样的白色矩形。只需android:background使用您想要的任何背景颜色将标签添加到 FrameLayout,并将徽标保存为透明 PNG。

于 2011-04-16T21:03:42.907 回答
1

我会这样做,使用相对布局在背景中有一个 ImageView,在此之上还有一个包含其余布局的相对布局

这样图像就可以保持正确的尺寸

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:scaleType="centerInside"
        android:src="@drawable/splash_picture"/>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal">
        <!-- rest of your layout -->
    </LinearLayout>
</RelativeLayout>
于 2011-04-16T21:38:24.107 回答