zoukankan      html  css  js  c++  java
  • 安卓开发

    学习margin和padding的区别,参考菜鸟教程的资料:

    首先margin代表的是偏移,比如marginleft = "5dp"表示组件离容器左边缘偏移5dp; 而padding代表的则是填充,而填充的对象针对的是组件中的元素,比如TextView中的文字 比如为TextView设置paddingleft = "5dp",则是在组件里的元素的左边填充5dp的空间! margin针对的是容器中的组件,而padding针对的是组件中的元素,要区分开来! 下面通过简单的代码演示两者的区别:

    比较示例代码如下:

    <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:id="@+id/btn1"     
            android:layout_height="wrap_content"    
            android:layout_width="wrap_content"    
            android:text="Button"/>    
        <Button    
            android:paddingLeft="100dp"     
            android:layout_height="wrap_content"    
            android:layout_width="wrap_content"    
            android:text="Button"    
            android:layout_toRightOf="@id/btn1"/>    
            
        <Button    
            android:id="@+id/btn2"     
            android:layout_height="wrap_content"    
            android:layout_width="wrap_content"    
            android:text="Button"    
            android:layout_alignParentBottom="true"/>    
        <Button    
            android:layout_marginLeft="100dp"     
            android:layout_height="wrap_content"    
            android:layout_width="wrap_content"    
            android:text="Button"    
            android:layout_toRightOf="@id/btn2"     
            android:layout_alignParentBottom="true"/>    
            
    </RelativeLayout>
  • 相关阅读:
    TP5报如下的错误 Indirect modification of overloaded element of thinkpaginatorCollection has no effect【转】
    PHPnumber_format()函数的使用
    蓝桥杯-PREV28-地宫取宝
    HihoCode-1053-居民迁移
    HihoCode-1323-回文字符串
    蓝桥杯-PREV3-带分数
    HDU-6312-Game
    HDU-6438-Buy and Resell
    CF-1117C-Magic Ship
    HDU-2802-F(N)
  • 原文地址:https://www.cnblogs.com/20193898liufa/p/14890472.html
Copyright © 2011-2022 走看看