【问题标题】:Hold a ImageView exactly in place XML将 ImageView 准确地保存在 XML 位置
【发布时间】:2020-03-09 08:12:59
【问题描述】:

我有以下问题,我想一个ImageView的(谷歌的Play按钮),添加到我的对话框,它停留在地方,不管哪个设备的应用程序正在运行。 P>

下面是它应该是什么样子: P>

这是什么样子在某些设备上:

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

我怎么能告诉应用从来不把黄金面纱上面的图片? P>

【问题讨论】:

  • 在哪个文件夹里没有你的地方goldversiondialog.png? SPAN>
  • @米希尔绘制跨度>
  • 它工作像预期的,如果你把它的网络连接。 drawable-hdpi文件夹?跨度>

标签: java android xml imageview


【解决方案1】:

这样做:

<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,保持纵横比,高度随宽度变化。

【讨论】:

    猜你喜欢
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 2013-05-14
    • 2018-01-31
    相关资源
    最近更新 更多