2

我最近尝试定位 imageview 的 x 和 y 坐标但没有运气,似乎在 Gingerbread 中没有办法做到这一点。然后我决定尝试填充和边距,但是当我设置它们时,它会缩小我的图像视图。我设置了 250dp 的左填充,图像视图变得很小。layout_height 和 width 设置为 wrap_content。我不确定发生了什么事。有谁知道为什么设置填充/边距会缩小图像视图?

4

2 回答 2

14

您混淆了边距和填充。边距是视图之外的区域,而填充会影响边距的内容。

边距和填充示例

如果您设置填充,那么它将影响您的可用内容区域,并且假设您设置了 ScaleType,它将缩小您的图像以适应可用空间。

现在,您说您已经尝试了边距,但边距将完全符合您的要求。

例如,如果您想从左上角ImageView放置,您可以执行以下操作:10dp

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <ImageView
        android:id="@+id/my_image_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:src="@drawable/my_image_id"
        />
</RelativeLayout>

请记住,这是10dp相对于parent边界放置的。如果您的父布局也有填充,那么这将影响您的内容放置。

于 2012-08-29T01:23:50.893 回答
1

如果缩小意味着图片的比例混乱,那么你应该使用

android:scaleType="centerInside"

这将防止比率发生变化

于 2012-08-29T00:57:54.917 回答