【问题标题】:Position a linearlayout at the bottom of the view在视图底部放置一个线性布局
【发布时间】:2014-04-29 06:24:25
【问题描述】:

我希望在我的视图底部有一个包含不同小部件的“工具栏”......每个小部件都由一个代表图标的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>

但我的工具栏实际上出现在之前布局的底部。知道如何解决这个问题吗?

【问题讨论】:

  • 在该布局中,您有 3 张图片,然后在该布局下,您有一个图像和文本堆叠在另一个图像和文本之上,对吗?
  • @zgc7009 说的是哪个布局?

标签: android android-layout android-xml gravity


【解决方案1】:

使用RelativeLayout 进行外部布局。当你这样做时,你的内部视图(在你的例子中:LinearLayout)可以有一个属性: layout_alignParentBottom

其实你的问题已经在这里描述过了:How to align views at the bottom of the screen?

【讨论】:

  • 你的意思是我的根布局应该是相对布局?
【解决方案2】:

如果您将父视图用作RelativeLayout,则可以使用android:layout_alignParentBottom = "true" 将布局放置在屏幕底部。

【讨论】:

    【解决方案3】:

    我建议您不要使用这种方法,而是像这样使用 actionBar

    您可以在本教程中找到所需的一切 Working with Action Bar

    【讨论】:

    • 其实我想有更好的设计图像,操作栏可以吗?
    • 可以,只要选择你想要的图标
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-11
    • 2011-07-22
    • 2016-01-07
    • 2013-11-05
    • 1970-01-01
    相关资源
    最近更新 更多