1、布局管理
組件在activity中呈現(xiàn)的方式,包含組件大小、間距、對齊方式
Android提供了兩種布局的實現(xiàn)方式:
- .在xml配置文件中聲明,通過setContentView(R.layout.main)方法呈現(xiàn)在activity中,通過findViewById()方法獲得組件實例。(一般推薦這種方式)
- 動態(tài)生成組件以及設(shè)置相關(guān)布局
2、線性布局 LinearLayout
線性布局是最簡單的一種布局,將子組件按照垂直或者水平方向進(jìn)行布局。文章來源:http://www.zghlxwxcb.cn/news/detail-506672.html
- 方向控制:android:orientation屬性來控制,有vertical(垂直)和horizontal(水平)兩種
- 對齊方式:android:gravity屬性來控制,有top、bottom、left、right、center等
- 比例分割:weight
3、登錄界面
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textView1"
android:layout_width="13dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="username:"
android:layout_marginLeft="15dp"/>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="13dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="password:"
android:layout_marginLeft="15dp"/>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button1"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginRight="10dp"
android:text="submit" />
<Button
android:id="@+id/button2"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:text="reset" />
</LinearLayout>
</LinearLayout>
文章來源地址http://www.zghlxwxcb.cn/news/detail-506672.html
到了這里,關(guān)于【Android】UI布局之線性布局(登錄界面代碼)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!