Android - Resource 之 Layout 小结

时间:2023-03-10 03:24:35
Android - Resource 之 Layout 小结

Layout定义了一个Activity的UI框架,或者是一个UI的组件。

文法如下:

?xml version="1.0" encoding="utf-8"?>
<ViewGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@[+][package:]id/resource_name"
android:layout_height=["dimension" | "fill_parent" | "wrap_content"]
android:layout_width=["dimension" | "fill_parent" | "wrap_content"]
[ViewGroup-specific attributes] >
<View
android:id="@[+][package:]id/resource_name"
android:layout_height=["dimension" | "fill_parent" | "wrap_content"]
android:layout_width=["dimension" | "fill_parent" | "wrap_content"]
[View-specific attributes] >
<requestFocus/>
</View>
<ViewGroup >
<View />
</ViewGroup>
<include layout="@layout/layout_resource"/>
</ViewGroup>

ViewGroup:LinearLayout、RelativeLayout、FrameLayout等

View:TextView、Button、CheckBox等等

<requestFocus/>:指定焦点

android:id : "@+id/xx" 加号代表一个新的resource,编译工具aapt将会在R.java类中添加一个整数变量作为该resource的ID。如果已定义了一个ID resource()还没被使用,你可以用android:id来指代一个View。

你还可以自定义一个View或ViewGroup