android笔记一 控件属性

本文详细介绍了如何使用LinearLayout进行Android应用布局设计,包括按钮和列表视图的位置调整与尺寸控制。通过具体的XML代码示例展示了控件的排列方式及其属性设置。
<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_height="fill_parent"
    android:layout_width="fill_parent"    
    >

    <Button
        android:id="@+id/button_test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="60dp"
        android:layout_marginBottom="100dp"
        android:text="我是第1个控件"
        android:textSize="12sp" />

    <Button
        android:id="@+id/button_test1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="15sp"
        android:layout_below="@+id/button_test"
        android:paddingLeft="20sp"
        android:layout_gravity="right"
        android:text="我是第2个控件"
        android:textSize="12sp" />

    <ListView
        android:id="@+id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button_test1" />

</LinearLayout>

 

<Button
        android:id="@+id/button_test"
        android:layout_width="wrap_content"//大小刚刚可以包住文本
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"//相对上方控件的距离
        android:layout_marginLeft="40dp"//相对左边控件的距离
        android:layout_marginRight="60dp"//相对右边控件的距离
        android:layout_marginBottom="100dp"//相对下方控件的距离
        android:text="我是第1个控件"
        android:textSize="12sp" />//设置文本的大小

    <Button
        android:id="@+id/button_test1"
        android:layout_width="match_parent"//宽度跟父窗口是一样的
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:paddingTop="15sp"
        android:layout_below="@+id/button_test"//使该控件一直在第一个控件的下方
        android:paddingLeft="20sp"//文本相对控件左边的距离
        android:gravity="right"//表示文本的对齐方式
        android:text="我是第2个控件"
        android:textSize="12sp" />

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值