【问题标题】:Aligning an image in graphical layout在图形布局中对齐图像
【发布时间】:2012-10-01 08:26:07
【问题描述】:

您好,我想知道如何将框对齐到 android 屏幕的底部?我已经把盒子做成了一个 9patch png 图像,但实际图像和边框之间仍然存在一些差距。谁能帮帮我吗?我的意思是,控制图像大小的图形布局屏幕上的蓝色边框与实际图像之间存在实际间隙。请原谅我的英语。

这是蓝色框的xml代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/background" />

<ImageView
    android:id="@+id/topbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/top_bar" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/topbar"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="95dp"
    android:src="@drawable/icon_green" />

<ImageView
    android:id="@+id/box"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="23dp"
    android:src="@drawable/box" />

</RelativeLayout>

【问题讨论】:

  • 这里是完整的 xml。希望你能帮忙:)
  • 你能添加你当前布局的图片链接吗?您在上一个 ImageView 中有 android:layout_marginBottom="23dp"
  • Yul 我还不能添加图片,因为我有足够的声誉,但我会检查边缘部分
  • 所以你可以添加一个自我回答并检查它。

标签: android xml image xml-drawable


【解决方案1】:

不完全理解问题,但尝试添加

 android:adjustViewBounds="true" 

到您的 ImageViews。

我看到 id 为“box”的视图与底部对齐,底部边距为 23dp。这将在屏幕底部创建一个间隙;)

【讨论】:

    【解决方案2】:

    问题解决了,伙计们。实际上,我猜这个盒子是悬停的,因为盒子的宽度在屏幕上太大了。在图形布局上切换到更大的屏幕(5.4 英寸,以前是 4 英寸)后,框就在底部。感谢您的帮助 :) 好吧,这很愚蠢,抱歉大惊小怪,我是 android 新手。

    【讨论】:

    • 在较小的设备上,这不是解决方案。我认为盒子(imageview)变大并缩小并保持空白的解决方案是“adjustViewBounds”。为 Android 开发几乎要牢记所有设备、屏幕尺寸等。
    • 啊,现在我看到了 adjustViewBounds 是如何工作的,它使图像的比例保持固定,而不管屏幕尺寸如何,对吧?这肯定会派上用场。谢谢大脑。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 2013-08-23
    • 2015-04-18
    • 2016-11-11
    • 2017-01-20
    相关资源
    最近更新 更多