您的位置:首页 > 移动开发 > Android开发

Android学习笔记1 创建一个activity

2014-03-24 11:40 302 查看
内容均为google官方教程的学习笔记

教程地址:http://developer.android.com/intl/zh-cn/training/basics/firstapp/building-ui.html#LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="horizontal" >

<EditText
android:id="@+id/edit_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send" />

</LinearLayout>


实际运行效果



要点:

1 对view可以指定宽度和长度为wrap_content, 即view可以根据其content的长宽来动态适应. 比如上图的text里的输入, 如果换行, 也会撑大text的高度.

2 线性布局中可以用weight属性来分配和填充布局的剩余空间, 如果只有一个view设置了weight, 那就会填充满剩余空间, 需要注意的是设置weight后需要指定宽度为0, 即不再需要固定宽度.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐