簡體   English   中英

將線性布局放置在視圖的底部

[英]Position a linearlayout at the bottom of the view

我希望在視圖的底部有一個不同小部件的“工具欄” ...每個小部件都由代表圖標的ImageView和作為描述的TextView組成。 這是XML代碼:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/linear_layout_shelves"
    android:background="@drawable/final_shelves"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_marginLeft="70dp"
        android:layout_marginRight="65dp"
        android:layout_marginTop="@dimen/first_shelf_margin_top"
        android:orientation="horizontal" >
        <ImageView
            android:id="@+id/image_11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_weight="1"
            android:src="@drawable/image1"
            android:clickable="true"/>
        <ImageView
            android:id="@+id/image_12"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_weight="1"
            android:src="@drawable/image2"
            android:clickable="true" />
        <ImageView
            android:id="@+id/image_13"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_weight="1"
            android:src="@drawable/image3"
            android:clickable="true" />
    </LinearLayout>


    <!-- "Tools" : Cancel, delete, details -->
    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
         >

        <!-- Cancel Widget -->
        <RelativeLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/delete_widget"
            android:layout_weight="1"
            android:visibility="visible">
                <ImageView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/cancel_icon"
                android:src="@drawable/cancel_128"
                android:clickable="true" />

               <TextView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Cancel"
                android:layout_above="@id/cancel_icon"
                android:textColor="@color/white"
                android:clickable="true" />
        </RelativeLayout>

        <!-- Delete Widget -->
        <RelativeLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/cancel_widget"
            android:layout_weight="1"
            android:visibility="visible">

            <ImageView
               android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/delete_icon"
                android:src="@drawable/delete_blue_128"
                android:clickable="true" />

            <TextView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Delete Card"
                android:textColor="@color/white"
                android:layout_below="@id/delete_icon"
                android:clickable="true" /> 
         </RelativeLayout>

        <!-- Show details Widget -->
        <RelativeLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/show_details_widget"
            android:layout_weight="1"
            android:visibility="visible">

            <ImageView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/show_details_icon"
                android:src="@drawable/info_128"
                android:clickable="true" />

           <TextView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Show card details"
                android:layout_below="@id/show_details_icon"
                android:textColor="@color/white"
                android:clickable="true" />

            </RelativeLayout> 

    </LinearLayout>
</LinearLayout>

但是我的工具欄實際上出現在前一個布局的底部。 任何想法如何解決該問題?

RelativeLayout用於外部布局。 在執行此操作時,您的內部視圖(在您的情況下為:LinearLayout)可以具有一個屬性: layout_alignParentBottom

實際上,這里已經描述了您的問題: 如何在屏幕底部對齊視圖?

如果您將父視圖用作RelativeLayout則可以使用android:layout_alignParentBottom = "true"將布局放置在屏幕底部。

而不是使用此方法,我建議您像這樣使用actionBar

在此處輸入圖片說明

您可以在本教程中找到所需的全部內容使用操作欄

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM