簡體   English   中英

相對布局如何與其他元素而不是父元素對齊

[英]Relative layout how to align to other element instead of parent

我有一個相對的布局,在該布局中我已經對齊了幾乎所有想要的元素,但是在右下角有兩個元素(textView和禁止照片的圖標),它們與父級對齊,而父級不是照片。

我想將那些元素與我所擁有的圖像的底部對齊:

這里有一個 截圖

預期成績: 圖像2

矩形是我要textView和相機禁止圖標的地方!

這是xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="142dp"
        android:layout_gravity="center"
        android:layout_margin="@dimen/card_margin"
        android:elevation="3dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingTop="10dp"
        card_view:cardCornerRadius="@dimen/card_specie_radius">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">


            <com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
                android:id="@+id/Avaliation"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/plantName"
                android:layout_marginStart="92dp"
                android:layout_marginTop="15dp"
                android:text="Avalie a fotografia" />

            <com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/plantPhoto"
                android:textColor="@color/base"
                android:layout_marginTop="4dp"
                android:layout_toStartOf="@+id/cameraForbiden"
                android:text="TextView" />

            <ImageView
                android:id="@+id/reportImg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/color_cursor_white" />

            <ImageView
                android:id="@+id/plantPhoto"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_marginRight="16dp" />

            <ImageView
                android:id="@+id/userIcon"
                android:layout_width="15dp"
                android:layout_height="15dp"
                android:layout_alignParentBottom="true"
                android:layout_below="@id/plantPhoto"
                android:src="@drawable/ic_user"
                />


            <com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
                android:id="@+id/plantName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/plantPhoto"
                android:textColor="@color/nephritis"
                android:textSize="18sp" />

            <ImageView
                android:id="@+id/starIcon"
                android:layout_width="23dp"
                android:layout_height="23dp"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/plantName"
                android:src="@drawable/ic_star"
                android:layout_marginLeft="10dp"
                />


            <ImageView
                android:id="@+id/cameraForbiden"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_toRightOf="@+id/plantName"
                android:layout_marginLeft="10dp"
                android:src="@drawable/ic_no_photos"
                android:layout_below="@id/plantPhoto"
                />

            <com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
                android:id="@+id/username"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/plantPhoto"
                android:textColor="@color/base"
                android:layout_marginEnd="29dp"
                android:layout_marginTop="8dp"
                android:layout_toEndOf="@+id/userIcon"
                android:layout_toLeftOf="@+id/userIcon"
                android:paddingLeft="10px"/>
        </RelativeLayout>

    </android.support.v7.widget.CardView>

</LinearLayout>

使用以下代碼:

    <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

    <ImageView
                    android:id="@+id/plantPhoto"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginRight="16dp" />

     <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentBottom="true"
                android:layout_margin="5dp"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/userIcon"
                    android:layout_width="15dp"
                    android:layout_height="15dp"
                    android:src="@drawable/ic_user"
                    />

              <com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
                    android:id="@+id/plantName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/nephritis"
                    android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>

暫無
暫無

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

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