簡體   English   中英

在父級的線性布局的底部對齊相對布局

[英]Align Relative Layout at bottom of Linear Layout in Parent

我有線性布局作為相對布局的父級。相對布局由一些按鈕和東西組成。我想在線性布局的底部對齊相對布局(包含按鈕的面板)。線性布局僅包括ImageView,然后相對布局應在底部對齊。

但是,當我嘗試在相對布局中設置android:layout_alignParentBottom="true" ,IDE提示代碼是錯誤的。我如何實現這一點,請幫忙

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="250dp"
        android:scaleType="fitStart"
        android:src="@drawable/jellyfish" />

    <RelativeLayout

        android:layout_width="318dp"
        android:layout_height="164dp"
        android:layout_margin="5dp"
        android:background="@drawable/backgrad"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="34dp"
            android:onClick="clickme"
            android:text="Button" />

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginTop="16dp"
            android:layout_toLeftOf="@+id/button1"
            android:onClick="textclick"
            android:src="@drawable/text" />

        <Button
            android:id="@+id/button2"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/button1"
            android:layout_alignBottom="@+id/button1"
            android:layout_centerHorizontal="true"
            android:onClick="wmark"
            android:text="Save" />


    </RelativeLayout>

</LinearLayout>

在此處輸入圖片說明

可能重復: 如何在LinearLayout中實現alignParentBottom =“ true”屬性

當您設置android:layout_alignParentBottom="true" ,您嘗試使用LinearLayout的方法。 但是LinearLayout不提供alignParentBottom

重復的答案說要替換

android:layout_alignParentBottom="true"

通過

android:gravity="bottom"

將以下內容添加到父級線性布局xml:

android:gravity="bottom"

我已經回答了另一個這樣的話題,解決方案是將一個權重為1的視圖放置在相對布局上方,如下所示:

    <View android:id="@+id/emptySpace"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    />

嘗試將ImageView封裝在線性布局中,然后添加

android:layout_alignParentBottom="true"

在您的相對布局中。

暫無
暫無

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

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