Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent gradient issue

I have layout with google map fragment in FrameLayout. Also, i placed the new view over the map with gradient background. Layout:

<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. start/end and center colors. This gradient draws with 2 light lines:

<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. start/end and center colors. This gradient draws with a 1 light line:

<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

  1. 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"/>
    

enter image description here

How can i draw a smooth linear gradient from black (or semi transparent black) to a full transparent?

I tried hardware acceleration on/off, 'getWindow().setFormat(PixelFormat.RGBA_8888);' Nothing helps me.

Update 1 I created a simple app at github. https://github.com/ralexey/TestApp Just an activity with color background and gradient over it.

like image 393
Alexey Rogovoy Avatar asked Nov 08 '22 06:11

Alexey Rogovoy


1 Answers

add this line in your gradient android:centerY="y%p" it may help you

<?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>
like image 186
prakash ubhadiya Avatar answered Nov 15 '22 05:11

prakash ubhadiya