- Android Shape Drawables Tutorial
- Have you ever wanted to reduce your Android application’s size or make it look more interesting? If yes, then you should try out ShapeDrawables.
- Why should you use ShapeDrawables?
- Are there any disadvantages?
- Let’s start coding
- Create a simple gradient ShapeDrawable in XML
- Circle android all circles
- About
- Circle android all circles
- About
- How to Create Circle Image View using CardView in Android App
- Step 1: Create a new Project
- Step 2: Adding the CircleImageView dependency
- Step 3: Modify activity_main.xml
- Android CardView Attributes:
- Step 4: MainActivity.java file
- Output:
- Conclusion:
- rodrigosimoesrosa / circle_drawable_shadow.xml
Android Shape Drawables Tutorial
Nov 3, 2017 · 6 min read
Have you ever wanted to reduce your Android application’s size or make it look more interesting? If yes, then you should try out ShapeDrawables.
First, we will go over the advantages and disadvantages of the ShapeDrawables. Then we will create some Drawables that could be used in your app and lastly for the grand finale we will try to replicate a gradient as can be seen in the Spotify app/website.
Why should you use ShapeDrawables?
When you want to use PNG or JPEG images in your applic a tion, you have to provide multiple copies of the same image for different screen densities. That, of course, clutters your app with copies of the same image. Yes, sometimes that is the path we have to choose because we can’t use Drawables for every single case, but we can dramatically reduce our application’s size if we can use Drawables instead. ShapeDrawables are a series of commands that tell how to draw something on the screen. That is why they can be resized and stretched as much as we want, without losing any quality. We can recolor and manipulate them even when the app is running and use the same ShapeDrawable multiple times in our app. Since ShapeDrawables are a subclass of the Drawable abstract class, we can use them in methods where a Drawable is expected. Click for the documentation of the ShapeDrawable.
Are there any disadvantages?
Of course, just like I have mentioned before we can’t use them in every case. I have said before that ShapeDrawable class is a subclass of the Drawable abstract class. There are other subclasses as well and every one of them has its own use case. You can click here to check other Drawable types and figure out which one is right for your case. Another issue is that they took a bit longer to draw than a Bitmap since there is a lot of parsing and drawing going on behind the scenes. But I think that is not a huge problem if your Drawables are simple.
My opinion is that you should use Drawables (ShapeDrawables) wherever you can, because they are easy to modify and they don’t take much space.
Let’s start coding
First let’s take a look at a simple example and then we will recreate a gradient as can be seen in the Spotify app/website.
Create a simple gradient ShapeDrawable in XML
First create a new drawable resource file.
Right click on res/drawable > New > Drawable resource file > give your file a name > use shape as a root element > click Ok
Shape root element defines that this is a ShapeDrawable.
This is how the first example looks like:
Источник
Circle android all circles
A small Android library allowing you to have a smooth and customizable circular ProgressBar like whatsapp and Tez app, it can be use while uploding or downloading file.
I decided to do this because I was really tired to find progressbar like whatsapp and gradient color progressbar and also you can contribute more color style, or new idea to me.
I took reference or take some code from CircleProgress and change it as i need. also add code for set vector image as background and gradient colors.
Add it in your root build.gradle at the end of repositories:
Add the dependency:
You can either simply use the AdCircleProgress widge from this library on a regular ProgressBar .
Simply replace your ProgressBar with AdCircleProgress , and remember to apply corresponding style and attribute for correct behavior.
For example, to create a first AdCircleProgress like whatsapp:
Second AdCircleProgress in which you can change adpgb_finished_stroke_width like below code:
Third AdCircleProgress in which you can change custom:adpgb_inner_drawable means you can change image or vector image in inner circle like below code:
Fourth AdCircleProgress in which you can change custom:adpgb_show_text=»true» means if you want to show progress in percentage like below code:
Fifth AdCircleProgress in which you can add gradient color for progressbar app:adpgb_gradient_color_one=»@color/colorOne» app:adpgb_gradient_color_two=»@color/colorTwo» like below code:
Do not forget to add xmlns:custom custom attr in your root layout :
About
A small Android library allowing you to have a smooth and customizable circular ProgressBar.
Источник
Circle android all circles
Rich feature Circular SeekBar (Circle, Semi-circle, and Ellipse) for Android.
This library is based on CircularSeekBar of Matt Joseph (devadvance). But the original author seems to have stopped maintaining (last commit was in 2016), so I decide to take it up by myself.
I made it build on Android Studio (Gradle), then fix & add more features to the library.
The features I add
- Support float progress, instead of integer only.
- Refactor the name of the attributes, to avoid conflicts.
- Disable the seek pointer, make it work like a circular progress bar.
- Some other bug fixes for Matt’s CircularSeekBar.
- Customize the shape of progress end (butt, round, square)
- Use a arc to represent the pointer, you can custom the arc angle.
- Negative progress support.
- Other small features.
Copy sources and attrs.xml in module circularSeekBar to your project.
CircularSeekBar support following attributes:
This library is based on CircularSeekBar of Matt Joseph (devadvance). But the original author seems to have stopped maintaining (last commit was in 2016), so I decide to take it up by myself. Thanks to Matt for the work!
This part provides general solution to any types of libraries:
- GitHub Actions: Quick Start, Workflow commands and Upload Release Asset repo are official documents I use to write the CI check and releasing workflows.
- Márton B.: Publishing Android libraries to MavenCentral in 2021: It is a great learning material for how to upload library to sonatype maven central. Another post (LINK) also could used as a reference.
- Official Maven Central document Gradle to learn how to publish artifacts.
- Signature: Maven Central requires signature for library to release. GPG and The Signing Plugin are two official document for how to sign the library, this will correct some error or outdated information in Márton’s article.
- Also Timber of Jake Wharton is a great library to learn how to use a generic solution for public libraries. My mvn-push.gradle is actually forked from Timber repo, and it’s really universal that could be used on many different types of libraries.
About
Custom circular SeekBar (Circle, Semi-circle, and Ellipse) for Android
Источник
How to Create Circle Image View using CardView in Android App
LAST UPDATED: AUGUST 26, 2021
We can easily use an Android ImageView to show Image in our App. But what if we want to show a circular image on our App screen, how will we do it? It is not possible to do it using a simple ImageView as it is not made for doing this type of stuffs, so to do so we have to use an external library.
One such external library is the hdodenhof module which provides the hdodenhof CircleImageView using which we can create a simple CircleImageView, but or for this tutorial we will use CardView to create a circular image view our our app in android studio.
So let’s create a simple Circular ImageView using CardView in our android app.
Step 1: Create a new Project
Open Your Android Studio Click on «Start a new Android Studio project«(Learn how to setup Android Studio and create your first Android project)
Choose «Empty Activity» from the project template window and click Next
Enter the App Name, Package name, save location, language(Java/Kotlin, we use Java for this tutorial ) and minimum SDK(we are using API 19: Android 4.4 (KitKat) )
Next click on Finish button after filling the above details
Now wait for the project to finish building.
Step 2: Adding the CircleImageView dependency
To show the circular image in our app we also have to implement the hdodenhof CircleImageView in our app, to do so follow the below steps.
Go to Gradle Scripts -> build.gradle (Module: app) section and import below dependencies and click the «sync Now» shown at the top:
Step 3: Modify activity_main.xml
So before applying any changes to the activity_main.xml file we need an image which we will show in the CircleImageView, so you can download any image and put the image in the app -> res -> drawable and give it a suitable name.
Now go to app -> res -> layout -> activity_main.xml and remove the default code then change the layout to Android RelativeLayout and inside the layout add CardView as shown below:
Now inside the CardView we will add a simple ImageView with following attributes:
android:src=»https://www.studytonight.com/post/@drawable/img» : Where img is the name of the image which we have pasted in the drawable folder.
android:scaleType=»centerCrop» : It means to scale the image uniformly (maintain the image’s aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
The complete code of activity_main.xml is show below:
Android CardView Attributes:
Following are the few main attributes available in the CardView:
Attribute | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
android:layout_width | It is used to set the width of the card view | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
android:layout_height | It is used to set the width of the card view | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
app:cardCornerRadius |
xml version = » 1.0 » encoding = » utf-8 » ?> |
layer-list xmlns : android = » http://schemas.android.com/apk/res/android » > |
Shadow —> |
item > |
shape android : shape = » oval » > |
padding |
android : bottom = » 1dp « |
android : left = » 1dp « |
android : right = » 1dp « |
android : top = » 1dp »/> |
solid android : color = » #00CCCCCC »/> |
shape > |
item > |
item > |
shape android : shape = » oval » > |
padding |
android : bottom = » 1dp « |
android : left = » 1dp « |
android : right = » 1dp « |
android : top = » 1dp »/> |
solid android : color = » #10CCCCCC »/> |
shape > |
item > |
item > |
shape android : shape = » oval » > |
padding |
android : bottom = » 1dp « |
android : left = » 1dp « |
android : right = » 1dp « |
android : top = » 1dp »/> |
solid android : color = » #20CCCCCC »/> |
shape > |
item > |
item > |
shape android : shape = » oval » > |
padding |
android : bottom = » 1dp « |
android : left = » 1dp « |
android : right = » 1dp « |
android : top = » 1dp »/> |
solid android : color = » #30CCCCCC »/> |
shape > |
item > |
item > |
shape android : shape = » oval » > |
padding |
android : bottom = » 1dp « |
android : left = » 1dp « |
android : right = » 1dp « |
android : top = » 1dp »/> |
solid android : color = » #50CCCCCC »/> |
shape > |
item > |
Background —> |
item > |
shape |
android : shape = » oval » > |
solid android : color = » @android:color/white »/> |
shape > |
item > |
layer-list > |
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник