我想要一个"工具栏"在我的视图底部的不同小部件...每个小部件都由一个代表图标的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>
但我的工具栏实际上只显示在上一个布局的底部。知道如何解决问题吗?
答案 0 :(得分:5)
使用RelativeLayout
作为外部布局。当你这样做时,你的内部视图(在你的情况下:LinearLayout)可以有一个属性:
layout_alignParentBottom
实际上,您的问题已在此处说明:How to align views at the bottom of the screen?
答案 1 :(得分:2)
如果您将父视图用作RelativeLayout
,则可以使用android:layout_alignParentBottom = "true"
将布局放置在屏幕底部。
答案 2 :(得分:1)