在 XML 中,a 的等价物Div是ViewGroup.
例如:LinearLayout等RelativeLayout。
ViewGroups 可以包含视图和控件,例如TextView:Button和EditView.
更多 ViewGroup 子类
我创建了一个我认为您要问的示例:
我用 aLinearLayout来保存我们的视图和控件。
然后我用android:gravity="center_horizontal", on our LinearLayout, 让孩子们居中。
<LinearLayout 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"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".MainActivity" >
<TextView
android:layout_width="200dp"
android:gravity="center_horizontal"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<EditView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</LinearLayout>
这是它的样子:
