实验报告
实验目的 (Experiment Purpose)
- Know how to create and run an Android APP
- Get familiar with the file structure of an Android project
实验环境 (Experiment Environment)
- software: java version “18.0.2”,Android Studio 2021.2.1 Patch 2
- Operating system:Window 10
实验内容 (Experiment content)
3.1 Experimental data
Set the string in Android/app/res/layout/value/strings.xml.
在 Android/app/res/layout/value/strings.xml中制定字符串。
<resources>
<string name="app_name">Greeting</string>
<string name="hello">hello</string>
<string name="my">my</string>
<string name="name">name</string>
<string name="is">is</string>
<string name="firstname">HuiTing</string>
<string name="lastname">Ji</string>
</resources>
3.2 Experimental process
Set the layout in Android/app/res/layout/activity_main.xml.
在 Android/app/res/layout/activity_main.xml文件中设定布局。
As shown in the figure above, Greeting is generally a vertical layout, including two horizontal layouts:
The second line is a horizontal layout, including three TextViews, namely, “my”, “name”, and “is”.
The third line is a horizontal layout, including two TextViews, namely, my last name and first name.
如上图Greeting总体是垂直布局,其中包含两个水平布局:
第二行是水平布局,包含了三个TextView,分别是“my”,“name”,“is”
第三行是水平布局,包含了两个TextView,分别是我的姓和名。
3.3 Experimental results
The results display and code implementation are shown as follows:
结果展示和代码实现如下图:
3.4 Analysis
- Set layout via , vertical layout to use statement “android:orientation=“vertical” ”, and horizontal layout to use statement “android: orientation=" horizontal "”. Layouts and layouts allow nesting.
- Use the “android: textColor” method to set the color;
- use the “android:gravity” method to set the text alignment, which can be set to “center”,“fill” etc.
设定布局使用<LinearLayou>,垂直布局则使用语句"android:orientation=“vertical”“,水平布局则是用语句"android:orientation=“horizonal””。布局之间允许嵌套。
设定颜色使用"android:textColor"方法;
设定文本对齐方式使用"android:gravity"方法,可以设置为"center","fill"等。
实验小结 (Summary)
My thoughts and experiences
- The text displayed by TextView should not be directly defined in “Android: text” with double quotation marks, but should be specified in the “string.xml” file in the form of “id” and referenced with @.
- Nesting between layouts can make the structure of the page clearer and cleaner.
TextView展示的文字不应该直接在android:text中用双引号定义,而是应该在string.xml文件中通过id形式制定字符串,在使用@进行引用。
布局之间嵌套可以使页面的构架更加清晰整洁。
Shortcomings
You can use the color attribute to define the color for a single string to make the page more beautiful.
可以对单个字符串使用color属性定义颜色,使页面更加美观。