我有一个包含Google地图碎片的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>
- 起始/结束和中心颜色。这个渐变使用两条亮线绘制:
<color name="fade_start_color">#00000000</color>
<color name="fade_center_color">#4f000000</color>
<color name="fade_end_color">#ff000000</color>
- 起始/结束和中心颜色。这个渐变使用一条亮线绘制:
<color name="fade_start_color">#00000000</color>
<color name="fade_center_color">#6f000000</color>
<color name="fade_end_color">#ff000000</color>
The same behavior for gradient without center color:
<gradient android:angle="90" android:startColor="@color/fade_start_color" android:endColor="@color/fade_end_color" android:type="linear"/>
我该如何绘制一个从黑色(或半透明黑色)到完全透明的平滑线性渐变?
我尝试了硬件加速的开启和关闭,'getWindow().setFormat(PixelFormat.RGBA_8888);',但都没有帮助。
更新1: 我在Github上创建了一个简单的应用程序。 https://github.com/ralexey/TestApp 只是一个包含颜色背景和渐变效果的活动。
android:dither="true"
。 - prakash ubhadiyaandroid:centerY="50%p"
根据您的需求进行调整。 - prakash ubhadiya