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

Android Studio | note | Hello World | LinearLayout | TextView

2018-03-13 20:15 459 查看
**作为刚开始的入门的小白,以下内容仅作为笔记。

部分内容来自网络。**

知识点

LinearLayout

TextView

目标

利用线性布局对位置的处理。

实例

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.fanny.dome1.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello world ! " />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hi! " />
</LinearLayout>


实例如图:



若要改变文本的位置进行修改就是对线性布局的属性(下图所在位置)进行修改。



1.文本位置

左上角

默认文字即在左上角可无需修改。

右上角

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
**android:gravity="right"//VIP**
tools:context="com.fanny.dome1.MainActivity">


核心代码语句:

左下角

android:gravity="bottom"


右下角

android:gravity="bottom|right"


左居中

android:gravity="left|center"


右居中

android:gravity="right|center"


全居中

android:gravity="center"


底部居中

android:gravity="bottom|center"


android:gravity=”“ 是属于线性布局的一个属性,英译为重力,可对文本所在位置进行控制。

2.文本方向

android:orientation="vertical"




android:orientation="horizontal"




orientation为方向,vertical为垂直, horizontal 为水平方向。

3.文本内容

android:text="hi! "


android:text=” ” 双引号内的为显示的文本内容。

4.应用-个人名片



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center|bottom"
tools:context="com.fanny.dome1.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<
4000
span class="hljs-attribute">android:text="hello world ! " />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 来自一个大一小白的笔记 " />

</LinearLayout>


5.文件名的修改

直接对此处进行修改即可。

此处修改的位置一是页面的名称,二是APP的名称。

还可新建多个string,命名不同的 name,后来可直接引用,多处要修改的话,改这一个位置便可。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息