展会信息港展会大全

android:layout_weight和android:layout_gravity用法
来源:互联网   发布日期:2015-10-13 15:21:36   浏览:3199次  

导读:android:layout_weight用来分配更多的空间给该控件android:layout_gravity是用来设置该button相对与父view的位置带layout的都是相对于父控...

android:layout_weight用来分配更多的空间给该控件

android:layout_gravity是用来设置该button相对与父view的位置

带layout的都是相对于父控件而言.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical"

android:background="#D1EEEE"

android:paddingLeft="16dp"

android:paddingRight="16dp" >

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:hint="to" />

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:hint="subject" />

<SPAN style="COLOR: #ff9966">//android:layout_weight用来分配更多的空间给该控件</SPAN>

<EditText

android:layout_width="fill_parent"

android:layout_height="0dp"

android:layout_weight="1"

android:gravity="top"

android:hint="message" />

<SPAN style="COLOR: #ff9966">//默认位置是距做对齐</SPAN>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Defaultsend" />

<SPAN style="COLOR: #ff9900">//android:layout_gravity是用来设置该button相对与父view的位置</SPAN>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="right"

android:text="send" />

</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical"

android:background="#D1EEEE"

android:paddingLeft="16dp"

android:paddingRight="16dp" >

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:hint="to" />

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:hint="subject" />

//android:layout_weight用来分配更多的空间给该控件

<EditText

android:layout_width="fill_parent"

android:layout_height="0dp"

android:layout_weight="1"

android:gravity="top"

android:hint="message" />

//默认位置是距做对齐

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Defaultsend" />

//android:layout_gravity是用来设置该button相对与父view的位置

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="right"

android:text="send" />

</LinearLayout>

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港