在Android studio建立新页面
Res->layout->右键new->Activity->Empty Activity
1.布局三个按钮
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="150dp"
android:layout_height="88dp"
android:text="按钮1"></Button>
<Button
android:layout_width="150dp"
android:layout_height="88dp"
android:text="按钮2"></Button>
<Button
android:layout_width="150dp"
android:layout_height="88dp"
android:text="按钮3"></Button>
</LinearLayout>
此时默认水平布局
2.改成垂直布局
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" //靠边垂直(之后第4步时选择了horizontal水平布局)
android:gravity="center" //页面正中
3.在Button里改成正中(仅作对比实验,完成后回到2)
<Button
android:layout_width="150dp"
android:layout_height="88dp"
android:text="按钮1"
android:layout_gravity="center"></Button>
4.在linearlayout里放两个linearlayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ff00">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1256"
android:textSize="36sp"></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#00FFA6">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABCD"
android:textSize="36sp"></TextView>
</LinearLayout>
</LinearLayout>

5.页面平均分(layout_weight=“1”)
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ff00"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1256"
android:textSize="36sp"></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#00FFA6"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABCD"
android:textSize="36sp"></TextView>
</LinearLayout>

6.合并Linearlayout
先复制整个外层LinearLayout,然后到最底层粘贴,再用新的一个LinearLayout包住这两个LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ff00"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1256"
android:textSize="36sp"></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#00FFA6"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABCD"
android:textSize="36sp"></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#BBFF00"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RRDSD"
android:textSize="36sp"></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FF7700"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GGHH"
android:textSize="36sp"></TextView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ff00"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1256"
android:textSize="36sp"></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#00FFA6"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABCD"
android:textSize="36sp"></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#BBFF00"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RRDSD"
android:textSize="36sp"></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FF7700"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GGHH"
android:textSize="36sp"></TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>

7.更改app->manifests->AndroidManifest.xml文件
让intent-filter在Linear_Layout里,就不会还是出现上次运行的界面了
<activity android:name=".Linear_Layout">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
</activity>
8.运行

本文是关于Android设计与开发的课堂笔记,详细介绍了如何在Android Studio中创建新页面,包括从建立空活动开始,设置布局方向,调整按钮位置,利用layout_weight实现页面平均分配,以及如何合并LinearLayout和处理AndroidManifest.xml文件确保正确显示界面。

1037

被折叠的 条评论
为什么被折叠?



