Android 布局 - ImageView 对齐问题 [英] Android layout - alignment issue with ImageView

查看:23
本文介绍了Android 布局 - ImageView 对齐问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将图像放在 LinearLayout 的左上角,但图像边框和填充占据了窗口的整个宽度.

I'm trying to put an image at the top left of a LinearLayout, but with the image border and padding taking up the whole of the width of the window.

如果我尝试下面的 XML,我得到的图像带有边框和整个页面宽度的白色背景,除了图像最终居中,并且不会向左移动.

If I try the XML below, I get my image with its border and a white background across the whole width of the page, except that the image ends up centered, and doesn't move to the left.

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="left"
    android:src="@drawable/banner"
    android:background="@android:color/white"
    android:padding="@dimen/d_8px"
/>

layout_width 设置为 fill_parent<时,是否有一些我尚未发现的属性会强制图像在 ImageView 内左对齐/代码>?

Is there some attribute that I've not yet discovered that forces the image to be left aligned within the ImageView when the layout_width is set to fill_parent?

与此同时,我通过将 ImageView 放入另一个 LinearLayout 并在其右侧放置一个空的 TextView 来解决此问题占据其余的水平空间.

In the meantime, I've worked around this by dropping the ImageView inside another LinearLayout and dropping an empty TextView to its right that takes up the rest of the horizontal space.

推荐答案

我遇到了类似的问题,您今天早些时候对此进行了回复.这是在 Eclipse 插件与 XML 编辑器并排提供的屏幕设计"查看器上,还是在实际运行应用程序时遇到对齐问题?如果是前者,那似乎是插件中的一个错误,如果是后者,请尝试添加:

I was having a similar problem, to which you replied earlier today. Is this on "screen design" viewer provided by the Eclipse plugin side-by-side with the XML editor, or are you encountering the alignment problems when actually running the app? If the former, that appers to be a bug in the plugin, if the latter, try adding:

android:scaleType="fitStart"

从我读过的文档来看,这似乎最接近您的需要.

From the documentation I've read, that seems to be the closest to what you need.

这篇关于Android 布局 - ImageView 对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆