Java 将ImageView完全固定在XML中

Java 将ImageView完全固定在XML中,java,android,xml,imageview,Java,Android,Xml,Imageview,我有以下问题,我想添加一个ImageView(谷歌播放按钮)到我的对话框中,无论应用程序在哪个设备上运行,它都会保持不变 下面是它的外观: 这是某些设备上的外观: 以下是XML: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"

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

下面是它的外观:

这是某些设备上的外观:

以下是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,保持纵横比,这样高度会根据宽度变化。

执行以下操作:

<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
,保持纵横比,以便高度会根据宽度而变化。

您将goldversiondialog.png放置在哪个文件夹中?@Michiel drawable如果将其放在fi中,它是否能正常工作
drawable hdpi
folder?您将goldversiondialog.png放在哪个文件夹中?@Michiel drawable如果您将其放在fi中,它是否能正常工作<代码>可绘制hdpi文件夹?