簡體   English   中英

如何在 RelativeLayout 中的 LinearLayout 之上獲得 ImageView

[英]How to get an ImageView on top of a LinearLayout in RelativeLayout

我有一個復制按鈕的LinearLayout ,我想在此按鈕的右上角添加一個ImageView 因此,我決定將此LinearLayout放在RelativeLayout中,並在LinearLayout下方添加ImageView ,使其與LinearLayout對齊。 它工作得很好,除了ImageView似乎低於LinearLayout 我該如何解決?

我的代碼:

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

    <LinearLayout
        android:id="@+id/timetable"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_marginStart="20dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="10dp"
        android:layout_marginBottom="10dp"
        android:background="@drawable/button_card"
        android:clickable="true"
        android:focusable="true"
        android:gravity="center_vertical"
        android:onClick="openTimetable"
        android:orientation="vertical"
        android:stateListAnimator="@animator/item_elevation">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:contentDescription="@string/timetable_description"
            app:srcCompat="@drawable/ic_timetable"
            app:tint="@color/colorPrimary" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:clickable="false"
            android:text="@string/timetable"
            android:textAlignment="center"
            android:textColor="@color/colorPrimary"
            android:textStyle="bold" />
    </LinearLayout>

    <!-- This is the view that I want to be paced on top of the LinearLayout -->
    <ImageView
        android:id="@+id/timetable_notification"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/timetable"
        android:layout_alignEnd="@id/timetable"
        android:contentDescription="@string/notification_description"
        android:src="@drawable/ic_notification_dot" />
</RelativeLayout>

上面的代碼給出了這個:

在此處輸入圖像描述

右上角的紅點是ImageView 我希望將它放在LinearLayout的頂部。

問題的原因是給 Linearlayout 的高程

android:stateListAnimator="@animator/item_elevation"

此高度將 Z 順序設置在 Imageview 之上,因此您在 LinearLayout 后面看到 Imageview。

因此,在 Imageview 上應用相同的海拔也可以解決問題

暫無
暫無

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

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