【问题标题】:Gradient effect not showing in layout android渐变效果未在布局android中显示
【发布时间】:2015-04-10 10:49:25
【问题描述】:

您好,我正在我的 Android 应用中使用渐变效果。

在布局中,我使用了 2 个可绘制布局来放置一些视图的背景以应用渐变效果。

布局如下:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ProgressWheel="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="350dp" >

    <View
        android:id="@+id/music_individual_album_top_gradient"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/music_individual_album_top_gradient_height"
        android:layout_gravity="start"
        android:background="@drawable/album_option_gradient_top"
        />

    <ImageView
        android:id="@+id/imageviewIdAlbumCover"
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:scaleType="fitXY" />

    <RelativeLayout
        android:id="@+id/music_individual_album_option_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginTop="5dp"
        android:background="@drawable/album_option_gradient_bottom"
        android:gravity="bottom"
        android:weightSum="4" >

        <Button
            android:id="@+id/addqueueAlbum"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/music_individual_album_top_gradient_height"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/album_button_shape"
            android:gravity="center"
            android:paddingLeft="7dp"
            android:paddingRight="7dp"
            android:text="+Queue"
            android:textAllCaps="false"
            android:textColor="#ffffff" />

        <Button
            android:id="@+id/shareAlbum"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="5dp"
            android:layout_toRightOf="@+id/addqueueAlbum"
            android:background="@drawable/album_button_shape"
            android:gravity="center"
            android:paddingLeft="7dp"
            android:paddingRight="7dp"
            android:text="Share"
            android:textAllCaps="false"
            android:textColor="#ffffff" />

        <Button
            android:id="@+id/favouriteAlbum"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="5dp"
            android:layout_toRightOf="@+id/shareAlbum"
            android:background="@drawable/album_button_shape"
            android:drawableLeft="@drawable/favourite_heart"
            android:gravity="center"
            android:paddingLeft="7dp"
            android:paddingRight="7dp"
            android:text="122"
            android:textColor="#ffffff" />

        <ImageView
            android:id="@+id/moreAlbum"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerInParent="true"
            android:layout_marginRight="10dp"
            android:src="@drawable/more"
            android:visibility="gone" />
    </RelativeLayout>

    <ImageView
        android:id="@+id/album_play_queue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/albums_play" />
</FrameLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp" >
</LinearLayout>

在该布局中,我使用以下 xml 文件作为背景,其中包含渐变效果。

  1. album_option_gradient_bottom.xml
  2. album_option_gradient_top.xml

视图@+id/music_individual_album_top_gradient 具有来自album_option_gradient_top.xml 的渐变效果。但是在执行的时候,并没有体现出渐变效果。

1. album_option_gradient_bottom.xml

<?xml version="1.0" encoding="utf-8"?>

<gradient
    android:angle="90"
    android:endColor="#05ffffff"
    android:startColor="#F2000000"
    android:useLevel="true" />

<corners android:radius="0dp" />

2。 album_option_gradient_top.xml

<?xml version="1.0" encoding="utf-8"?>

<gradient
    android:angle="90"
    android:startColor="#05ffffff"
    android:endColor="#F2000000"
    android:useLevel="true" />

<corners android:radius="0dp" />

我期待图片的效果。

【问题讨论】:

    标签: android gradient android-drawable


    【解决方案1】:

    我没有发布整个布局,只是带有两个可绘制的图像供您参考以包含在您的布局中。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/imageView"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/ic_launcher" />
    
        <View
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="80dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/album_option_gradient_top"/>
    
        <View
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="80dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/album_option_gradient_bottom"/>
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 2021-07-30
      相关资源
      最近更新 更多