继昨天讲了的ConstraintLayout,今天要来介绍自己也常用的另外两个布局,LinearLayout以及RelativeLayout,首先从LinearLayout先开始。
LinearLayout(线性布局),严格来说又可分成两种布局方向,一种是水平方向的(vertical)以及垂直方向的(horizontal),首先先附上程序:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_marginTop="100dp"
android:layout_marginLeft="100dp"
android:padding="20dp"/>
</LinearLayout>
在最外层的layout,可以看到他的布局方向(orientation)是垂直方向(horizontal),若orientation这个属性改成vertical则是水平方向的,接着先来讲一些常用到的属性。
其中里面也蛮多通用於其他布局的属性,主要有:
(元件内外部距离)
(元素位置控制)
RelativeLayout(相对布局),主要可透过相对位置(相对布局、元件)来调整、设定其元件的位置。
<RelativeLayout 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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="100dp"
android:layout_marginTop="100dp"
android:text="Hello World!"
android:padding="50dp"/>
</RelativeLayout>
(与元件对齐):(="@+id/????")?为你要对齐的元件的id。
(与父层对齐):(="true")
(与对应父层方向拉开的距离 margin):(="????dp")你要拉开?dp的距离,或者你想用sp、dpi等都可以。
更多属性请参阅:Android Developers/RelativeLayout
<<: [13th][Day10] waiting group
回顾30天,也让我回忆了今年从金融业被抓去做开发工程师的日子。这30天中,讲述了Vue的基本介绍、性...
if event.postback.data[:9] == "Schedule:"...
tags: Vuejs 动态组件 ✐ 动态组件可以帮助我们动态切换组件,例如在网页的多标签介面中常见...
现在开始要开始介绍我们使用的工具了,工欲善其事必先利其器,这一篇首先带大家来了解一下我们要使用的Dj...
[Day15] LocalStorage and Event Delegation 需要用到的技巧与...