-->
当前位置:首页 > 题库 > 正文内容

移动应用开发 实验报告2 线性布局管理器设计

Luz4年前 (2021-08-08)题库1157

一、实验目的

了解用户界面设计概念;

掌握线性布局的添加方法;

熟悉线性布局管理器的常见属性,并能够设置属性。

二、实验内容

1.创建新的Android项目

2.res/layout/activity_main.xml中的RelativeLayout改为LinearLayout,并在里面添加若干个TextView组件

3.自定义每个组件的样式

三、实验原理

image.png

线性布局是最基本的一种局部方式,其本身有两种形式:垂直(vertical)排列和水平(horizontal)排列。

 

四、实验代码及结果

 

<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"

    tools:context=".MainActivity"   >

 

    <TextView

        android:id="@+id/textView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Luz"

        android:textColor="#22BFFF"   />

 

    <TextView

        android:id="@+id/textView2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/textView1"

        android:layout_below="@+id/textView1"

        android:layout_marginTop="36dp"

        android:text="admin@hyluz.cn"

        android:textColor="#32CD32"

        android:textSize="25sp"   />

 

 

 

    <TextView

        android:id="@+id/textView3"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/textView2"

        android:layout_below="@+id/textView2"

        android:layout_marginTop="44dp"

        android:text="www.hyluz.cn"

        android:textColor="#FFD700"   />

    <ImageView

        android:id="@+id/imageView2"

        android:layout_width="278dp"

        android:layout_height="261dp"

        android:layout_marginTop="90dp"

        android:src="@drawable/yaobuqi"   />

</LinearLayout>

image.png

五、试验分析(思考)

1.线性布局(LinearLayout)

  线性布局可以分为两种形式,首先第一种横向线性布局,第二种纵向线性布局,总而言之都是以线性的形式,一个个排列出来的,纯线性布局的缺点是很不方便修改控件的显示位置,所以开发中经常会以线性布局与相对布局嵌套的形式设置布局。

2.相对布局(RelativeLayout)

  相对布局是android布局中最为强大的,首先它可以设置的属性是最多了,其次它可以做的事情也是最多的。android手机屏幕的分辨率五花八门所以为了考虑屏幕自适应的情况所以在开发中建议大家都去使用相对布局,它的坐标取值范围都是相对的所以使用它来做自适应屏幕是正确的。

3.帧布局(FrameLayout)

  原理是在控件中绘制任何一个控件都可以被后绘制的控件覆盖,最后绘制的控件会盖住之前的控件。如图所示界面中先绘制的ImageView 然后在绘制的TextViewEditView 所以后者就覆盖在了前者上面。

4.绝对布局(AbsoluteLayout)

  使用绝对布局可以设置任意控件的在屏幕中 X Y 坐标点,和帧布局一样后绘制的控件会覆盖住之前绘制的控件,笔者不建议大家使用绝对布局还是那句话因为android的手机分辨率五花八门所以使用绝对布局的话在其它分辨率的手机上就无法正常的显示了。

5.表格布局(TableLayout)

  在表格布局中可以设置TableRow,可以设置表格中每一行显示的内容以及位置 ,可以设置显示的缩进,对齐的方式。

 


发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。