英文:
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:
<?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>
答案1
得分: 1
那最好使用 ConstraintLayout
。它比 RelativeLayout
更灵活,而 RelativeLayout
则具有传统小部件。
英文:
That's better use ConstraintLayout
.it's more flexible than RelativeLayout
while RelativeLayout
has legacy widget.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论