2016-11-08 130 views
2

我在FrameLayout中使用谷歌地圖片段進行佈局。另外,我用漸變背景將新視圖放在地圖上。 佈局:透明漸變問題

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    > 

    <com.google.android.gms.maps.MapView 
     android:id="@+id/mapView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

    <View 
     android:id="@+id/fadeTop" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/fade_height" 
     android:layout_gravity="top" 
     android:background="@drawable/list_fade_top"/> 
    <include layout="@layout/top_line_mid_gray"/> 

</FrameLayout> 

list_fade_top:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <gradient 
     android:angle="90" 
       android:startColor="@color/fade_start_color" 
       android:centerColor="@color/fade_center_color" 
       android:endColor="@color/fade_end_color" 
     android:type="linear"/> 
</shape> 
  1. 開始/結束和中心色。該梯度繪製與光2行:

<color name="fade_start_color">#00000000</color> <color name="fade_center_color">#4f000000</color> <color name="fade_end_color">#ff000000</color> enter image description here

  • 開始/結束和中心色。該梯度繪製用1光線路:
  • <color name="fade_start_color">#00000000</color> <color name="fade_center_color">#6f000000</color> <color name="fade_end_color">#ff000000</color> enter image description here

  • 相同的行爲對於梯度而不中心色:

    <gradient 
        android:angle="90" 
          android:startColor="@color/fade_start_color" 
          android:endColor="@color/fade_end_color" 
        android:type="linear"/> 
    
  • enter image description here

    how ca ñ我畫一個從黑色(或半透明黑色)到全透明的平滑線性漸變?我嘗試了開啓/關閉硬件加速,'getWindow()。setFormat(PixelFormat.RGBA_8888);'沒有任何幫助我。

    更新1 我在github上創建了一個簡單的應用程序。 https://github.com/ralexey/TestApp 只是一個具有彩色背景和漸變的活動。

    回答

    0

    試試這個下面的代碼:

    <?xml version="1.0" encoding="utf-8"?> 
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    
        <item> 
         <shape android:shape="rectangle" android:padding="10dp"> 
          <gradient 
           android:startColor="#00000000" 
           android:centerColor="#6f000000" 
           android:endColor="#ff000000" 
           android:angle="90" /> 
    
         </shape> 
        </item> 
    
    </layer-list> 
    
    +0

    感謝您的回答,但它並沒有幫助我。 –

    1

    在梯度android:centerY="y%p" 加入這一行,它可以幫助你

    <?xml version="1.0" encoding="utf-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="rectangle" > 
    
        <gradient 
         android:angle="90" 
         android:centerY="25%p" 
         android:centerColor="@color/fade_center_color" 
         android:endColor="@color/fade_end_color" 
         android:startColor="@color/fade_start_color" 
         android:type="linear" 
         android:dither="true" 
         android:useLevel="true" /> 
    
    </shape> 
    
    +0

    謝謝,但沒有幫助 –

    +0

    添加此行'android:dither =「true」' –

    +0

    結果是一樣的 https://github.com/ralexey/TestApp/blob/prakash_u/app/src/main /res/drawable/list_fade_top.xml –