控件与布局

1.控件布局的基本概念

所谓的控件布局方法,就是指控制控件在Activity的位置、大小、颜色以及其他控件样式属性的方法。

  使用xml布局文件完成控件布局;

  在java代码当中完成控件布局;


2.控件布局的种类

  一类布局
  linear Layout 线形布局  最简单
  relative Layout 相对布局  最常用
  另一类
  ListView 常用 

  GridView


3.距离单位 像素px  dp  sp 


每英寸的像素个数dpi(dots per inch)=height的平方加+width的平方之和的平方根  再除以size
dp=dip  换算公式px=dp*(dpi/160)
在dpi为160的屏幕上:1dp=1px

sp单位通常用于字体的大小
当用修改手机显示字体时,sp会随之更给
通常在控件的长宽 使用 dp  使用字体的大小使用sp

4.控件的外边距与内边距


外边距

layout_margin 外边距 
layout_marginTop上外外边距
layout_marginBotton 下外边距

layout_marginLeft 左边距

layout_marginRight 右边距

内边距

layout_padding 内边距

......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textVeiw1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:text="第一个TextView控件" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#00FF00"
        android:text="第二个TextView" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="40dp"
        android:background="#FF0000"
        android:text="hello world" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:background="#00FF00"
        android:paddingTop="30dp"
        android:text="hello world" />

</LinearLayout>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值