2016-05-13 104 views
3

我正在處理最奇怪的情況。我在佈局文件中有三個按鈕。其中一人投下陰影,兩人不投。即使我將android:elevation="10dp」添加到其中一個不投射陰影的按鈕,他們仍然不會。這裏是XML一個按鈕顯示陰影,兩個不顯示:我不知道爲什麼

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:showIn="@layout/activity_look"> 

    <Button 
     android:id="@+id/new_look" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@drawable/sel_ripple" 
     android:backgroundTint="@color/colorAccent" 
     android:text="New look" 
     android:textColor="@color/white" 
     android:textSize="@dimen/look_btn"/> 

    <LinearLayout 
     android:id="@+id/btn_holder" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="@dimen/16dp" 
     android:layout_marginTop="@dimen/16dp" 
     android:orientation="horizontal" 
     android:padding="@dimen/8dp" 
     android:visibility="gone" 
     > 

     <Button 
      android:id="@+id/btn_yes" 
      android:layout_width="0dp" 
      android:layout_height="?attr/actionBarSize" 
      android:layout_marginRight="@dimen/32dp" 
      android:layout_weight="1" 
      android:background="@drawable/sel_ripple" 
      android:backgroundTint="@color/colorAccent" 
      android:text="@string/yes" 
      android:textColor="@color/white" 
      android:textSize="@dimen/look_btn" 
      /> 

     <Button 
      android:id="@+id/btn_no" 
      android:layout_width="0dp" 
      android:layout_height="?attr/actionBarSize" 
      android:layout_weight="1" 
      android:background="@drawable/sel_ripple" 
      android:backgroundTint="@color/colorAccent" 
      android:text="@string/no" 
      android:textColor="@color/white" 
      android:textSize="@dimen/look_btn" 
      /> 

    </LinearLayout> 
… 
</LinearLayout> 

ban_yesban_np不呈現出陰影的人。

+0

顯然,LinearLayout中的兩個無陰影按鈕以及其中的一些屬性使其成爲無陰影。我猜'android:padding =「@ dimen/8dp」'吃了兩個按鈕陰影。無論如何,我認爲你應該發佈一個圖像,所以其他人可以看到你的按鈕發生了什麼。 – sakiM

+0

感謝您的回覆。其實我添加了填充以查看這是否會有所幫助,所以這不是原因。如果有人想幫助他們,他們可以輕鬆地將代碼粘貼到他們的android studio中。這就是我顯示代碼的原因。 –

+0

不容易,這個XML包含太多的局部變量。您無法確認其他人是否能夠像您看到的那樣獲得相同的願景。 – sakiM

回答

1

將layout_marginBottom添加到佈局中的按鈕。這給一些空間按鈕來顯示它的海拔

<Button 
     android:id="@+id/btn_yes" 
     android:layout_width="0dp" 
     android:layout_height="?attr/actionBarSize" 
     android:layout_marginRight="@dimen/32dp" 
     android:layout_weight="1" 
     android:background="@drawable/sel_ripple" 
     android:backgroundTint="@color/colorAccent" 
     android:text="@string/yes" 
     android:textColor="@color/white" 
     android:textSize="@dimen/look_btn" 
     android:layout_marginBottom="8dp" 
     /> 

編輯:另一種方法是,在佈局上包裹的按鈕,使用

<LinearLayout 
    android:id="@+id/btn_holder" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="@dimen/16dp" 
    android:layout_marginTop="@dimen/16dp" 
    android:orientation="horizontal" 
    android:padding="@dimen/8dp" 
    android:visibility="gone" 
    android:clipToPadding="false" 
    > 

這可能是一個更好的解決辦法,如果你不不需要額外的保證金。

+0

這實際上工作!謝謝。容器怎麼沒有爲這個影子騰出空間?這是否與'GhostView'有關?如果你知道,你介意解釋嗎? –

+0

Hi @Nouvel Travay,給它增加另一個解決方案,這可能有助於解釋更多。你提供了一個很好的問題,所以我提出了你的問題。如果你喜歡我的回答,你也可以這樣做:) – Elye

+0

是的!這是一個更好的解決方案。 +1。不過,我仍然不明白其根本原因。我希望有人會解釋。 View類的源代碼很龐大。但是我仍然一直在尋找解釋。我喜歡理解事物。不只猴子看猴子。 –