【问题标题】:Android. ImageView won't position itself correctly安卓。 ImageView 无法正确定位自身
【发布时间】:2012-07-12 14:27:12
【问题描述】:

我正在尝试放置一个填充屏幕宽度的图像,具有实际图像的高度 (wrap_content),并且位于布局的最底部。

我写了下面的代码,但是在第二个 ImageView(带有 drawable/user_board 的那个)和屏幕的最底部之间,有一个小空间。为什么是这样?我已经尝试将填充和边距设置为 0dp,但它似乎没有起到作用。有什么想法吗?

代码如下:

<?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"
                android:id="@+id/LayoutBoard"
                android:noHistory="true"
                android:padding="0dp" >
    <ImageView
        android:src="@drawable/game_interface_background"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="matrix" />
    <ImageView
        android:src="@drawable/user_board"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"        
        android:layout_alignParentBottom="true"
        android:layout_margin="0dp"
        android:padding="0dp" />
</RelativeLayout>

【问题讨论】:

  • 您是否使用hierarchyviewer 来查看实际的填充和边距值在运行时的样子?
  • 嗯。不,我以前没用过,但我会用谷歌搜索它。谢谢。
  • 对这类事情非常有用。祝你好运!

标签: android imageview


【解决方案1】:

您的user_board 图像底部没有一些透明空间吗?或者您可以尝试在第二个ImageView 的填充字段中设置负值。

【讨论】:

  • 天哪!就是这样!我知道这很简单,我只是错过了。 :D 我真的很喜欢这个网站 :D
【解决方案2】:

使用android:scaleType="fitXY"ImageView 中包含的位图将调整大小以适应整个ImageView。因此,在您的两个 imageViews 中使用此属性可能会隐藏该空白区域。但是请记住,这不会保持图像的纵横比。有关android:scaleType 属性标签及其可能取值的更多信息,请参阅here

【讨论】:

  • 不。似乎不起作用。地狱正在发生 :)) 现在我很生气!我一定错过了什么,但我不知道是什么
  • @AndreiBogdan 我刚刚尝试了您的 xml 代码,并且似乎可以正常工作(当然使用不同的图像)。也许正在发生 Dmytro Titov 所说的。
猜你喜欢
  • 1970-01-01
  • 2019-06-18
  • 2018-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多