2017-06-28 150 views
0

在我的應用程序中,我有用戶配置文件的屏幕。它有兩個用於更改照片和密碼的按鈕。這裏有兩個按鈕Android。兩個完全相同的按鈕有不同的陰影

.... 

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginTop="19dp" 
     android:gravity="center_vertical"> 

     <ImageView 
      android:id="@+id/ivUserProfile" 
      android:layout_width="59dp" 
      android:layout_height="59dp"/> 

     <Button 
      style="@style/AppTheme.RaisedButton" 
      android:id="@+id/btnSwitchPhoto" 
      android:layout_width="match_parent" 
      android:layout_height="48dp" 
      android:theme="@style/AppTheme.White" 
      android:text="@string/change_avatar" 
      android:textSize="16sp" 
      android:textColor="@color/colorPrimary" 
      android:layout_marginRight="17dp" 
      android:layout_marginLeft="18dp"/> 

</LinearLayout> 

.... 

<Button 
    style="@style/AppTheme.RaisedButton" 
    android:id="@+id/btnSwitchPassword" 
    android:layout_width="wrap_content" 
    android:layout_height="48dp" 
    android:layout_marginTop="28dp" 
    android:theme="@style/AppTheme.White" 
    android:text="@string/changePassword" 
    android:textSize="16sp" 
    android:textColor="@color/colorPrimary"/> 

這些按鈕的代碼究竟裏面LinearLayout對其相同(除了文本),一個和他們看起來Android Studio中預覽相同。但是當我在設備上打開此屏幕時,我看到按鈕具有不同的陰影。這裏的屏幕截圖 Bottom button has more big shadow at the bottom

有沒有問題?

回答

-1
Looks andoid:layout_width is set to match_parent in the first case and in the second it is wrap_content. If it is wrap_content, according to the text, the button size shrinks. 
Moreover first one is inside linearlayout and the second one is outside and whether is it in any layout like Relativelayout? 
Attributes are different from each layout 
May be you keep both under same linearlayout and give a try by modifying only the text alone. 

Hope that helps!!! 
+0

我試過把兩個底部放在相同的父容器(LinearLayout)內,並將第二個按鈕的寬度設置爲match_parent,但仍然存在相同的問題。我也嘗試使用其他視圖(CardView和帶有自定義背景和高程的TextView)而不是按鈕,但問題仍然存在:第二個視圖的陰影大於第一個視圖的陰影 –

+0

按鈕中的文本較大比第一個。你嘗試第一個按鈕文本本身,如果你沒有得到任何影子,那是主要原因。 –

+0

我試圖設置相同的文字到兩個按鈕。它沒有幫助 –

0

採用Android:海拔= 「10dp」 兩個按鈕,看看它是否有助於

+0

它沒有幫助 –

2

這是正確的。

Android有兩種類型的陰影 - 環境光線和全向光線。兩者都會導致視圖投射陰影。第一種是從環境反射的光,幾乎無處不在,並在每個視圖周圍產生靜態的,簡單的灰色。

第二個是更具動態性,並導致陰影隨視圖的位置發生變化。全向光源位於屏幕上方。就像在現實世界中一樣,如果事情遠離光明,它的影子就會轉移得更多。很難注意到,但底部的按鈕在左側比在右側有更多的陰影。這是因爲它向左移動。

相關問題