将 ImageView 固定到位 XML

Hold a ImageView exactly in place XML

我有以下问题,我想在我的对话框中添加一个 ImageView(Google 播放按钮),无论该应用程序 运行 在哪个设备上,它都会保持不变。

它应该是这样的:

这是它在某些设备上的样子:

这里是 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/goProDialogImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:scaleType="fitXY"
        android:adjustViewBounds="true"
        android:src="@drawable/goldversiondialog"/>



    <ImageView
        android:id="@+id/googleplaybutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/goProDialogImage"
        android:layout_alignBottom="@+id/goProDialogImage"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:maxHeight="250dp"
        android:maxWidth="250dp"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="20dp"
        android:src="@drawable/gpbutton" />

</RelativeLayout>

如何告诉应用程序永远不要将图像放在金色面纱之上?

这样做:

<LinearLayout
            android:weightSum="1"
            android:gravity="end"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

    <ImageView
            android:id="@+id/googleplaybutton"
            android:layout_width="0dp"
            android:layout_weight="0.5"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/ic_logo" />
    </LinearLayout>

我已经删除了你的一些属性,关键是你需要在LinearLayout中使用weightSum并将weight应用到你的ImageView(我有给定0.5,你可以根据你的需要改变)。另外,不要将 android:scaleType 设置为 fitXY,保持纵横比,这样高度会根据宽度变化。