2016-02-27 131 views
1

我有以下布局(这里给出的简单设计):为什么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棒棒糖这个代码,屏幕看起来是这样的:

Screenshot of views badly placed

当我尝试Genymotion的Nexus相同的代码5奇巧,一切看起来都如预期,即第一视图(按钮)显示下方徽章(TextView的)

没有人有任何线索可能是错在这里?

感谢, Deveti

回答

4

elevation导致此问题。它在Lollipop中引入,并负责z排序。将您的布​​局复制到layout-v21并为该按钮设置android:elevation="0dp"

+0

它的工作,谢谢! 但是,我必须为TextView添加'android:elevation =“2dp”',然后显示徽章。不知道为什么,有趣。 –

+1

我忘了说,如果你不想创建多个布局,你可以在棒棒糖上用'View.setElevation(float)'设置海拔,或者在棒棒糖上用'ViewCompat.setElevation(float)'设置海拔。 –

0

我看到这个在另一个线程的地方,但你可以把这个到你的元素:

android:stateListAnimator="@null" 

为他人说,棒棒糖按钮海拔最高如此改变其覆盖其他元素。

例如在我的按钮视图下方我使用它,它表明:

<FrameLayout 
    android:id="@+id/ib_one_container" 

    android:layout_width="38dp" 
    android:layout_height="38dp" 
    android:layout_marginLeft="5.3dp" 
    android:orientation="vertical" 
    android:padding="3dp" 
    > 


    <Button 
     android:id="@+id/ib" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/white" 
     android:clickable="true" 
     android:gravity="center" 
     android:stateListAnimator="@null" 
     android:textSize="11sp" /> 


    <com.mobile.pomelo.UI.customViews.CustomDiagonalLineView 
     android:id="@+id/diagaonal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:visibility="visible" 

     /> 


</FrameLayout> 
相关问题