填充和利润率之间的Andr​​oid初学者差异 [英] Android beginner difference between padding and margin

查看:177
本文介绍了填充和利润率之间的Andr​​oid初学者差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在SO提到的问题。还检查了一个答案:
填充的边界内的空间,边框和实际的视图的内容之间。需要注意的是填充进入完全围绕内容:有填充在顶部,底部,右侧和左侧(可以是独立的)

I have referred questions on SO. ALso checked an answer:
Padding is the space inside the border, between the border and the actual view's content. Note that padding goes completely around the content: there is padding on the top, bottom, right and left sides (which can be independent).

页边距设在境外的空间,边框和旁边这个观点的其它元素之间。在图像中,边缘是整个对象以外的灰色区域。需要注意的是,像填充,保证金去完全围绕内容:有利润的顶部,底部,右侧和左侧

Margins are the spaces outside the border, between the border and the other elements next to this view. In the image, the margin is the grey area outside the entire object. Note that, like the padding, the margin goes completely around the content: there are margins on the top, bottom, right, and left sides.

此外,更多的填充和边距:

Also, more on padding and margins from:

http://developer.android.com/reference/android/view/ View.html
http://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html

但是,什么是根本填充和利润之间的区别?将取决于O.S.的行为不同和设备?
我有一个正常的,简单的布局。没有问题,code,使用了布局的文件夹 - 布局和布局sw600dp加上可绘制-4dpi。无保证金或填充不能进行布局,哪一个更合适呢?

But what is the difference fundamentally between padding and margins ? Would the behaviour differ depending on O.S. and devices?
I have a normal, simple layout. No problem with code, have used layout folders - layout and layout-sw600dp plus drawables-4dpi. Can't make layout without margin or padding, which one is more appropriate?

推荐答案

填充是内部/组件中。例如。 的TextView 按钮的EditText
例如。文本和边框

Padding is for inside/within components. Eg. TextView , Button, EditText etc.
Eg. space between the Text and Border

保证金是要应用于上外的组件。
例如。屏幕组件的​​左边缘与框之间的间距

Margin is to be applied for the on-outside of the components.
Eg. space between left edge of the screen and border of your component

视觉重presentation是伟大的:<一href="http://stackoverflow.com/questions/4619899/difference-between-a-views-padding-and-margin">Difference视图的空白和边距之间

Visual representation is great in : Difference between a View's Padding and Margin

使用填充,我已经看到了差异2.2,2.3和4.3表示,4.4
在这样的情况下:

With Padding, i have seen a difference in 2.2, 2.3 and say 4.3, 4.4
in such cases:

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="ASDFGHJKL" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="15dp"
        android:text="@string/hello_world" />

</RelativeLayout>  

此外,检查使用梦诗的:
<一href="http://developer.android.com/guide/topics/resources/more-resources.html">http://developer.android.com/guide/topics/resources/more-resources.html
<一href="http://developer.android.com/samples/BasicSyncAdapter/res/values/dimen.html">http://developer.android.com/samples/BasicSyncAdapter/res/values/dimen.html

Also, check the use of dimens:
http://developer.android.com/guide/topics/resources/more-resources.html
http://developer.android.com/samples/BasicSyncAdapter/res/values/dimen.html

这篇关于填充和利润率之间的Andr​​oid初学者差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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