Gradient Layout for dynamic gradients in android (without drawable) – Library

Published by Kapil Mohan on

Normally android uses a drawable shape resource for setting the gradient process, which sometimes is difficult as we need to create multiple resource files for using dynamic gradients.

Setting multiple gradients within Recycler view is also a tedious process. GradientLayout Library extends common Layouts (Linear, Relative, Table, etc…) and adds an attribute for mentioning gradient colors which enable users to design the layouts without creating any additional files.




Github Link:- https://github.com/csdodd/GradientLayout

dependencies {
    compile 'net.colindodd:gradientlayout:1.2'
}
<net.colindodd.gradientlayout.GradientRelativeLayout
    xmlns:gl="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    gl:start_color="@color/purple"
    gl:end_color="@color/blue"
    gl:orientation="TOP_BOTTOM">

</net.colindodd.gradientlayout.GradientRelativeLayout>

Available Layouts:

  • GradientAbsoluteLayout
  • GradientFrameLayout
  • GradientGridLayout
  • GradientLinearLayout
  • GradientRelativeLayout
  • GradientTableLayout
    final GradientLinearLayout layout = (GradientLinearLayout) view.findViewById(R.id.root);
    layout.setStartColor(Color.rgb(255,87,34))
          .setEndColor(Color.rgb(255,193,7))
          .setOrientation(GradientDrawable.Orientation.TR_BL);

Or just provide a single color and the layout will generate a gradient for you:

 final GradientLinearLayout layout = (GradientLinearLayout) view.findViewById(R.id.root);
    layout.setEndColor(Color.rgb(123,31,162));

Example for using with card layout

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:cardCornerRadius="15dp"
                app:cardPreventCornerOverlap="true"
                android:layout_marginTop="10dp">

                <net.colindodd.gradientlayout.GradientRelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:minHeight="100dp"
                    gl:start_color="@color/gradientLightYellow"
                    gl:end_color="@color/gradientOrange"
                    gl:orientation="LEFT_RIGHT"
                    android:padding="10dp">

<!--YOUR CODE HERE -->

                </net.colindodd.gradientlayout.GradientRelativeLayout>
            </android.support.v7.widget.CardView>




Libray Details:


Kapil Mohan

Like to add color to developers life and apps. Can create smile using Android, iOS, PHP, codeignitor, web technologies, etc... Feel free to contact me at [email protected] .