2014-12-29 65 views
8

我有一個小的佈局在API 19:4.2.2上正常工作,但無法使其在API 21:5.0.1上工作。RelativeLayout zorder棒棒糖

這裏的佈局:

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

    <Button 
     android:id="@+id/start_button" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:textStyle="bold" 
     android:textSize="30sp" 
     android:background="@color/start_button_bg" 
     android:textColor="@color/start_button_text" 
     android:text="@string/start_process"/> 

    <TextView 
     android:id="@+id/pro_icon" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="10dp" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:textColor="@android:color/white" 
     android:background="@drawable/pro_icon" 
     android:text="PRO" 
     android:gravity="center" 
     android:textAppearance="?android:attr/textAppearanceMedium"/> 

</RelativeLayout> 

真的簡單的東西。我只是想讓textview在相對佈局中位於Button之上。我知道相對佈局堆棧視圖按照它們在xml中添加的順序排列,但這似乎在棒棒糖上的工作方式不同。我無法讓TextView在按鈕上呈現。任何想法?

乾杯。

回答

15

A Button在Android 5.0+上默認有elevation;一個TextView沒有。小部件的標高將基本上覆蓋由RelativeLayoutFrameLayout設置的Z軸排序。

的選項有:

  1. 重新設計的用戶界面,沒有下令在Z軸部件,或

  2. Replace the StateListAnimator on your Button to modify or eliminate the elevation animation,或者

  3. 試圖改變TextView的高度,通過android:elevation,要高於Button

+0

沒有注意到海拔屬性。謝謝。另一方面,在改變視圖高程時有沒有辦法去除陰影? – Notbad

+0

@Notbad:可能吧,但我不知道這個技巧。 – CommonsWare