在安卓中如何使一个视图覆盖在其他所有视图之上?

huangapple go评论73阅读模式
英文:

make a view overlay all other views in android?

问题

<?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" />

            <!-- Other views are not translated to keep code concise -->

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

            <!-- Other views are not translated to keep code concise -->

        </RelativeLayout>

    </androidx.cardview.widget.CardView>

</FrameLayout>
英文:

I want to add facebook-like emoji to my application. I used a library called emojilike-android. It works but I can't see the whole part of the view. It goes under a text view called desc. I tried bringToFront() but couldn't achieve it. How to make emojiView overlay everything?

emojiView opens when long-click to like.

my xml file:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;FrameLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;&gt;
&lt;androidx.cardview.widget.CardView
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginLeft=&quot;0dp&quot;
android:layout_marginTop=&quot;7dp&quot;
android:layout_marginRight=&quot;0dp&quot;
android:layout_marginBottom=&quot;7dp&quot;
app:cardCornerRadius=&quot;0dp&quot;
app:cardElevation=&quot;@dimen/cardview_default_elevation&quot;&gt;
&lt;RelativeLayout
android:id=&quot;@+id/relative1&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;&gt;
&lt;ImageView
android:id=&quot;@+id/img&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;fill_parent&quot;
android:adjustViewBounds=&quot;true&quot;
android:transitionName=&quot;img&quot;
tools:ignore=&quot;UnusedAttribute&quot; /&gt;
&lt;ImageView
android:id=&quot;@+id/shadow_bottom&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;80dp&quot;
android:layout_alignBottom=&quot;@id/img&quot;
android:src=&quot;@drawable/bottom_shadow&quot; /&gt;
&lt;ProgressBar
android:id=&quot;@+id/progress_load_photo&quot;
style=&quot;@android:style/Widget.ProgressBar.Small&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_above=&quot;@+id/shadow_bottom&quot;
android:layout_alignParentTop=&quot;true&quot;
android:layout_alignParentEnd=&quot;true&quot;
android:layout_marginTop=&quot;251dp&quot;
android:layout_marginEnd=&quot;2dp&quot;
android:layout_marginBottom=&quot;298dp&quot; /&gt;
&lt;TextView
android:id=&quot;@+id/author&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;30dp&quot;
android:layout_below=&quot;@+id/img&quot;
android:layout_alignStart=&quot;@+id/title&quot;
android:layout_alignLeft=&quot;@+id/title&quot;
android:layout_alignTop=&quot;@+id/title&quot;
android:layout_alignEnd=&quot;@id/title&quot;
android:layout_alignRight=&quot;@+id/title&quot;
android:layout_marginRight=&quot;160dp&quot;
android:drawablePadding=&quot;10dp&quot;
android:ellipsize=&quot;end&quot;
android:gravity=&quot;bottom&quot;
android:maxLines=&quot;1&quot;
android:singleLine=&quot;true&quot;
android:text=&quot;Author&quot;
android:textColor=&quot;@android:color/white&quot; /&gt;
&lt;TextView
android:id=&quot;@+id/title&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_below=&quot;@+id/img&quot;
android:layout_marginLeft=&quot;16dp&quot;
android:layout_marginTop=&quot;10dp&quot;
android:layout_marginRight=&quot;16dp&quot;
android:fontFamily=&quot;sans-serif-light&quot;
android:text=&quot;Title&quot;
android:textColor=&quot;@color/colorTextTitle&quot;
android:textSize=&quot;17sp&quot;
android:textStyle=&quot;bold&quot; /&gt;
&lt;TextView
android:id=&quot;@+id/desc&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_below=&quot;@+id/title&quot;
android:layout_marginLeft=&quot;16dp&quot;
android:layout_marginTop=&quot;5dp&quot;
android:layout_marginRight=&quot;16dp&quot;
android:text=&quot;Desc&quot; /&gt;
&lt;TextView
android:id=&quot;@+id/time&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;24dp&quot;
android:layout_below=&quot;@+id/desc&quot;
android:layout_marginTop=&quot;10dp&quot;
android:layout_marginBottom=&quot;10dp&quot;
android:layout_toEndOf=&quot;@+id/title&quot;
android:drawablePadding=&quot;10dp&quot;
android:ellipsize=&quot;end&quot;
android:maxLines=&quot;1&quot;
android:singleLine=&quot;true&quot;
android:text=&quot;Time&quot; /&gt;  
&lt;LinearLayout
android:id=&quot;@+id/buttonPanel&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_below=&quot;@+id/desc&quot;
android:orientation=&quot;vertical&quot;&gt;
&lt;RelativeLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:padding=&quot;8dp&quot;&gt;
&lt;ImageView
android:id=&quot;@+id/like&quot;
android:layout_width=&quot;30dp&quot;
android:layout_height=&quot;30dp&quot;
android:src=&quot;@drawable/like&quot; /&gt;
&lt;ro.andreidobrescu.emojilike.EmojiLikeView
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;110dp&quot;
android:id=&quot;@+id/emojiView&quot;
android:layout_alignBottom=&quot;@+id/like&quot;
android:layout_marginBottom=&quot;10dp&quot;/&gt;
&lt;ImageView
android:id=&quot;@+id/comment&quot;
android:layout_width=&quot;30dp&quot;
android:layout_height=&quot;30dp&quot;
android:layout_marginStart=&quot;10dp&quot;
android:layout_toEndOf=&quot;@id/like&quot;
android:src=&quot;@drawable/ic_comment&quot; /&gt;
&lt;ImageView
android:id=&quot;@+id/save&quot;
android:layout_width=&quot;30dp&quot;
android:layout_height=&quot;30dp&quot;
android:layout_alignParentEnd=&quot;true&quot;
android:src=&quot;@drawable/ic_savee_black&quot; /&gt;
&lt;/RelativeLayout&gt;
&lt;TextView
android:id=&quot;@+id/likes&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginStart=&quot;8dp&quot;
android:textColor=&quot;@color/colorPrimaryDark&quot;
android:textStyle=&quot;bold&quot; /&gt;
&lt;RelativeLayout
android:id=&quot;@+id/commentsAndDate&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;&gt;
&lt;TextView
android:id=&quot;@+id/comments&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginStart=&quot;8dp&quot;
android:layout_marginTop=&quot;5dp&quot;
android:layout_marginBottom=&quot;10dp&quot;
android:text=&quot;@string/view_all_20_comments&quot;
android:textColor=&quot;@color/colorAccent&quot; /&gt;
&lt;FrameLayout
android:id=&quot;@+id/layoutDate&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_alignParentRight=&quot;true&quot;
android:layout_marginStart=&quot;8dp&quot;
android:layout_marginRight=&quot;5dp&quot;
android:layout_marginBottom=&quot;10dp&quot;
android:background=&quot;@drawable/round_white&quot;
android:padding=&quot;5dp&quot;&gt;
&lt;ImageView
android:layout_width=&quot;18dp&quot;
android:layout_height=&quot;18dp&quot;
android:layout_marginLeft=&quot;5dp&quot;
android:layout_marginRight=&quot;5dp&quot;
android:src=&quot;@drawable/ic_date&quot; /&gt;
&lt;TextView
android:id=&quot;@+id/publishedAt&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginLeft=&quot;27dp&quot;
android:layout_marginRight=&quot;10dp&quot;
android:text=&quot;01 January 1990&quot;
android:textColor=&quot;#606060&quot; /&gt;
&lt;/FrameLayout&gt;
&lt;/RelativeLayout&gt;
&lt;/LinearLayout&gt;
&lt;/RelativeLayout&gt;
&lt;/androidx.cardview.widget.CardView&gt;
&lt;/FrameLayout&gt; 

答案1

得分: 1

那最好使用 ConstraintLayout。它比 RelativeLayout 更灵活,而 RelativeLayout 则具有传统小部件。

英文:

That's better use ConstraintLayout.it's more flexible than RelativeLayout while RelativeLayout has legacy widget.

huangapple
  • 本文由 发表于 2020年4月5日 22:55:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/61044520.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定