我有以下布局(这里给出的简单设计):为什么FrameLayout在我的布局中没有正确设置Z顺序?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main">
<FrameLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hey, badge!"
android:layout_margin="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:layout_margin="10dp"
android:textSize="12sp"
android:background="#ff00ff"
android:padding="10dp"
android:layout_gravity="top|end"
/>
</FrameLayout>
</RelativeLayout>
我希望设置TextView的文本“AAAA”充当按钮徽章,也就是被放置在按钮在其右上角,情况并非如此。
相反,当我尝试上的HTC One M7棒棒糖,或Genymotion的Nexus 6棒棒糖这个代码,屏幕看起来是这样的:
当我尝试Genymotion的Nexus相同的代码5奇巧,一切看起来都如预期,即第一视图(按钮)显示下方徽章(TextView的)
没有人有任何线索可能是错在这里?
感谢, Deveti
它的工作,谢谢! 但是,我必须为TextView添加'android:elevation =“2dp”',然后显示徽章。不知道为什么,有趣。 –
我忘了说,如果你不想创建多个布局,你可以在棒棒糖上用'View.setElevation(float)'设置海拔,或者在棒棒糖上用'ViewCompat.setElevation(float)'设置海拔。 –