繁体   English   中英

需要有关Android布局的说明

[英]Need explanation about Android layouts

我想创建一个这样的视图:

在此输入图像描述

我尝试了这种布局架构:

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView> // The blue top bar

    <ScrollView android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" ></ScrollView>

    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:orientation="vertical">

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal">
        </TextView>

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal">
        </TextView>

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Description"
            android:gravity="center_horizontal">
        </TextView>

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal">
        </TextView>

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Place"
            android:gravity="center_horizontal">
        </TextView>

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal">
        </TextView>

    </LinearLayout>

    <RelativeLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:gravity="bottom">

        <ImageView android:layout_width="wrap_content"
           android:layout_height="40dp"
           android:clickable="false"
           android:scaleType="center" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:gravity="left"
            android:orientation="horizontal" >

            <Button
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_gravity="center_vertical"
                android:text="Button 1" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_gravity="center_vertical"
                android:text="Button 2" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_gravity="center_vertical"
                android:text="Button 3" />

        </LinearLayout>

    </RelativeLayout>

</RelativeLayout>

但由于某些原因,这不起作用,首先它不会在底栏中显示我想要的按钮。

我是Android开发人员的初学者,所以请帮助我。

  1. id分配给“Place”组件,以便稍后在放置按钮时可以引用此id:

      <LinearLayout android:id="@+id/placeLayout" ... /> 
  2. 在相对布局中,您可以通过以下方式告诉您的按钮位于id = placeLayout的组件下:

      <Button android:id="@+id/button1" android:layout_below="@+id/placeLayout" ... /> 
  3. 如果您希望一个按钮与另一个按钮正确并位于placeLayout组件下,请将其写入:

      <Button android:id="@+id/button2" android:layout_below="@+id/placeLayout" android:layout_toRightOf="@+id/button1" ... /> <Button android:id="@+id/button3" android:layout_below="@+id/placeLayout" android:layout_toRightOf="@+id/button2" ... /> 

以下是完整的参数列表您可以用来“告诉”每个元素必须放在哪里: http//developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html

我的建议,使用线性布局并使用“android:weightSum”(主要布局)和“android:layout_weight”(内部视图)属性,它可能在第一时间很复杂,但后来它将是最好的方法适合任何屏幕。 检查此线程: Android中的线性布局和权重

使用该技术,您将告诉主布局内的每个内部视图(或布局)应填充多少空间。

即:如果主要布局有android:weightSum = 1并且每个内部视图都有android:layout_weight = 0.33,那么它会强调每个内部视图填充可用总空间的1/3。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM