Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要关于Android布局的解释吗_Android_Layout - Fatal编程技术网

需要关于Android布局的解释吗

需要关于Android布局的解释吗,android,layout,Android,Layout,我想创建如下视图: 我尝试了这种布局架构: <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView> // The blue top bar <ScrollView android:layout_width="fill_pare

我想创建如下视图:

我尝试了这种布局架构:

<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开发的初学者,所以请帮助我

  • id分配给“放置”组件,以便您可以在稍后放置按钮时参考此id:

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

           <Button
            android:id="@+id/button1"
            android:layout_below="@+id/placeLayout"
            ... />
    
    
    
  • 如果希望一个按钮位于另一个按钮的右侧,并位于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"
           ...
        />
    
    
    

  • 下面是一个完整的参数列表,您可以使用它来“告诉”每个元素必须放置的位置:

    我的建议,使用线性布局,并使用“android:weightSum”(主布局)和“android:layout\u weight”(内部视图)属性,一开始可能会很复杂,但以后它将是适合任何屏幕的最佳方法。 检查此线程:

    使用这种技术,您可以告诉主布局中的每个内部视图(或布局)它应该填充多少空间


    i、 e:如果主布局的android:weightSum=1,而每个内部视图的android:layout\u weight=0.33,则表示每个内部视图占可用总空间的1/3。

    您也可以在内部布局中应用相同的技术:)(对于按钮)。