linearlayout

linearlayout布局如何设置

小亿
131
2024-02-18 16:18:21
栏目: 编程语言

在Android中,可以使用XML来设置LinearLayout布局。以下是一个示例:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 1"/>

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 2"/>

</LinearLayout>

在这个示例中,我们创建了一个垂直方向的LinearLayout布局,并在其中包含了两个Button。可以通过设置android:orientation属性来指定LinearLayout的方向(vertical或horizontal),通过设置android:layout_width和android:layout_height属性来确定布局的宽度和高度。通过设置子元素的android:layout_width和android:layout_height属性来确定子元素的尺寸。

0
看了该问题的人还看了