繁体   English   中英

使视图覆盖 android 中的所有其他视图?

[英]make a view overlay all other views in android?

我想在我的应用程序中添加类似 facebook 的表情符号。 我使用了一个名为 emojilike-android 的库。 它有效,但我看不到视图的整个部分。 它位于名为 desc 的文本视图下。 我尝试了 bringToFront() 但无法实现。 如何让 emojiView 覆盖一切?

长按点赞会打开 emojiView。

我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="7dp"
        android:layout_marginRight="0dp"
        android:layout_marginBottom="7dp"
        app:cardCornerRadius="0dp"
        app:cardElevation="@dimen/cardview_default_elevation">

        <RelativeLayout
            android:id="@+id/relative1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/img"
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:adjustViewBounds="true"
                android:transitionName="img"
                tools:ignore="UnusedAttribute" />

            <ImageView
                android:id="@+id/shadow_bottom"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:layout_alignBottom="@id/img"
                android:src="@drawable/bottom_shadow" />

            <ProgressBar
                android:id="@+id/progress_load_photo"
                style="@android:style/Widget.ProgressBar.Small"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/shadow_bottom"
                android:layout_alignParentTop="true"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="251dp"
                android:layout_marginEnd="2dp"
                android:layout_marginBottom="298dp" />

            <TextView
                android:id="@+id/author"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_below="@+id/img"
                android:layout_alignStart="@+id/title"
                android:layout_alignLeft="@+id/title"
                android:layout_alignTop="@+id/title"
                android:layout_alignEnd="@id/title"
                android:layout_alignRight="@+id/title"
                android:layout_marginRight="160dp"
                android:drawablePadding="10dp"
                android:ellipsize="end"
                android:gravity="bottom"
                android:maxLines="1"
                android:singleLine="true"
                android:text="Author"
                android:textColor="@android:color/white" />


            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/img"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="10dp"
                android:layout_marginRight="16dp"
                android:fontFamily="sans-serif-light"
                android:text="Title"
                android:textColor="@color/colorTextTitle"
                android:textSize="17sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/desc"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/title"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="5dp"
                android:layout_marginRight="16dp"
                android:text="Desc" />


            <TextView
                android:id="@+id/time"
                android:layout_width="wrap_content"
                android:layout_height="24dp"
                android:layout_below="@+id/desc"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:layout_toEndOf="@+id/title"
                android:drawablePadding="10dp"
                android:ellipsize="end"
                android:maxLines="1"
                android:singleLine="true"
                android:text="Time" />  

            <LinearLayout
                android:id="@+id/buttonPanel"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/desc"
                android:orientation="vertical">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="8dp">

                    <ImageView
                        android:id="@+id/like"
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:src="@drawable/like" />

                    <ro.andreidobrescu.emojilike.EmojiLikeView
                        android:layout_width="match_parent"
                        android:layout_height="110dp"
                        android:id="@+id/emojiView"
                        android:layout_alignBottom="@+id/like"
                        android:layout_marginBottom="10dp"/>

                    <ImageView
                        android:id="@+id/comment"
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:layout_marginStart="10dp"
                        android:layout_toEndOf="@id/like"
                        android:src="@drawable/ic_comment" />

                    <ImageView
                        android:id="@+id/save"
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:layout_alignParentEnd="true"
                        android:src="@drawable/ic_savee_black" />

                </RelativeLayout>

                <TextView
                    android:id="@+id/likes"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:textColor="@color/colorPrimaryDark"
                    android:textStyle="bold" />


                <RelativeLayout
                    android:id="@+id/commentsAndDate"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:id="@+id/comments"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="5dp"
                        android:layout_marginBottom="10dp"
                        android:text="@string/view_all_20_comments"
                        android:textColor="@color/colorAccent" />

                    <FrameLayout
                        android:id="@+id/layoutDate"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_marginStart="8dp"
                        android:layout_marginRight="5dp"
                        android:layout_marginBottom="10dp"
                        android:background="@drawable/round_white"
                        android:padding="5dp">

                        <ImageView
                            android:layout_width="18dp"
                            android:layout_height="18dp"
                            android:layout_marginLeft="5dp"
                            android:layout_marginRight="5dp"
                            android:src="@drawable/ic_date" />

                        <TextView
                            android:id="@+id/publishedAt"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="27dp"
                            android:layout_marginRight="10dp"
                            android:text="01 January 1990"
                            android:textColor="#606060" />

                    </FrameLayout>

                </RelativeLayout>
            </LinearLayout>

        </RelativeLayout>

    </androidx.cardview.widget.CardView>


</FrameLayout> 

最好使用ConstraintLayout 。它比RelativeLayout更灵活,而RelativeLayout具有旧版小部件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM