android基础之LinearLayout布局

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"

     >

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="button1"  

    />

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="button2"

    />

<Button

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:text="Button3"

    />

</LinearLayout>

android基础之LinearLayout布局

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"

     >

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="button1"  

    />

<LinearLayout android:orientation="vertical"

 android:layout_width="fill_parent"

 android:layout_height="wrap_content"

 >

 <Button

 android:text="Button2"   

 android:layout_width="wrap_content"

 android:layout_height="wrap_content"

/>

<Button

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:text="Button3"

    />

</LinearLayout>

</LinearLayout>

android基础之LinearLayout布局

Layout_weight属性:

所有的组件都有这个属性,不设置的情况下默认为0,其属性表示当前有多大视图就占据多大视图

如果其值高于0,则表示将父视图中的可用空间进行分割

示例代码如下:

<?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="vertical"

     >

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="button1" 

    android:layout_weight="1" 

    />

<Button

    android:text="button4"

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:layout_weight="1"

    />

</LinearLayout>

android基础之LinearLayout布局

线性布局中常用的属性:

1:gravity:每个组件默认其值为左上角对齐。这个属性可以调整组件对齐方式比如如何向左。向右或者居中对齐等、

2:padding边距的填充,也称内边距.指的是当前布局与包含的组件之间的边距

android:paddingTop

android:paddingBottom

android:paddingLeft

android:paddingRight

android:padding表示周围四方向个边距统一调整

3:layout_margin:外边距。指的是与其他组件之间的边距。

android:layout_marginTop

android:layout_marginBottom

android:layout_marginLeft

android:layout_marginRight

android:layout_margin表示设置四方向边距统一调整

一个比较综合的例子:

<?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="vertical"

     >

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="button1" 

    android:layout_gravity="bottom" 

    android:paddingTop="10dp"

    />

<Button

    android:text="button4"

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:layout_gravity="bottom"

    android:layout_marginLeft="50dp"

    android:layout_marginTop="30dp"

    />

<Button

    android:text="button2"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_gravity="bottom"  

    android:paddingLeft="60dp"

    android:paddingBottom="60dp"

   />

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="button3"

    android:layout_gravity="right"

    />

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="button6"

    android:layout_gravity="right"

    android:layout_marginRight="40dp"

    android:layout_marginTop="40dp"

    />

</LinearLayout>

android基础之LinearLayout布局

标题名称:android基础之LinearLayout布局
URL链接:https://www.cdcxhl.com/article2/jcjdoc.html

成都网站建设公司_创新互联,为您提供网站制作网站改版全网营销推广软件开发关键词优化品牌网站设计

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

搜索引擎优化