保证金/填充萎缩的ImageView [英] Margin/Padding Shrinks ImageView
问题描述
我最近尝试位置的的ImageView X和Y,没有运气坐标,看来是没有办法做到这一点姜饼。然后,我决定尝试填充和利润,但是当我将它们设置,它收缩我的ImageView。我订的250dp左填充和图像视图变得很小。的layout_height和宽度被设定为wrap_content。我不知道这是怎么回事。有谁知道为什么设置填充/保证金将缩小的ImageView的?
I recently tried to position an imageview's x and y coordinates with no luck, it seems there is no way to do it in Gingerbread. I then decided to try out paddings and margins, but when I set them, it shrinks my imageview. I set a left padding of 250dp and image view became tiny. The layout_height and width are set to wrap_content. I'm not sure what's going on. Does anyone know why setting a padding/margin would shrink an imageview?
推荐答案
你混淆margin和padding。保证金是您的视图外的区域,而填充影响到内容的在的保证金。
You're confusing margin and padding. Margin is the area outside of your view, while padding affects the content inside your margin.
如果你设置填充,那么它会影响您的可用内容区域,并假设你有一个ScaleType集,这将缩小图像缩小以适合可用空间。
If you set padding, then it is going to affect your available content area, and assuming you have a ScaleType set, it's going to shrink your image down to fit the available space.
现在,你说你已经试过的利润,但利润会做你问什么。
Now, you say you've tried margins, but margins will do exactly what you're asking.
例如,如果你想要一个的ImageView
放在 10dp
从左上角,你可以做一些事情像这样的:
For example, if you wanted an ImageView
placed 10dp
from the top-left corner, you can do something like this:
<?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
关于在父
边界。如果你的父母布局还具有填充,那么这会影响你的内容刊登。
Keep in mind that this places it 10dp
with respect to the parent
boundaries. If your parent layout also has padding, then that will affect your content placement.
这篇关于保证金/填充萎缩的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!