-
Notifications
You must be signed in to change notification settings - Fork 56
Added How to use Coil Image Loading Library. #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,11 +5,17 @@ import androidx.fragment.app.Fragment | |||||||||||||||||||
| import android.view.LayoutInflater | ||||||||||||||||||||
| import android.view.View | ||||||||||||||||||||
| import android.view.ViewGroup | ||||||||||||||||||||
| import android.widget.ImageView | ||||||||||||||||||||
| import coil.api.load | ||||||||||||||||||||
| import coil.transform.BlurTransformation | ||||||||||||||||||||
| import coil.transform.CircleCropTransformation | ||||||||||||||||||||
| import coil.transform.GrayscaleTransformation | ||||||||||||||||||||
| import coil.transform.RoundedCornersTransformation | ||||||||||||||||||||
| import java.io.File | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| class CoilFragment : Fragment() { | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add links to the project repo and documentation? kotlin-libraries-playground/kotlin-jvm/src/main/kotlin/playground/Markdown.kt Lines 17 to 25 in ff3ae6a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have now added the references. |
||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| override fun onCreateView( | ||||||||||||||||||||
| inflater: LayoutInflater, container: ViewGroup?, | ||||||||||||||||||||
| savedInstanceState: Bundle? | ||||||||||||||||||||
|
|
@@ -18,4 +24,49 @@ class CoilFragment : Fragment() { | |||||||||||||||||||
| return inflater.inflate(R.layout.fragment_coil, container, false) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||||||||||||||||||||
amaan118921 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
| super.onViewCreated(view, savedInstanceState) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // initializing the imageViews | ||||||||||||||||||||
amaan118921 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| val ivFile: ImageView = view.findViewById(R.id.ivFile) | ||||||||||||||||||||
| val ivUrl: ImageView = view.findViewById(R.id.ivUrl) | ||||||||||||||||||||
| val ivDrawable: ImageView = view.findViewById(R.id.ivDrawable) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // loading image into imageView through coil using different methods | ||||||||||||||||||||
|
|
||||||||||||||||||||
| //Loading from a URL | ||||||||||||||||||||
| ivUrl.load("https://via.placeholder.com/600/92c952") | ||||||||||||||||||||
|
|
||||||||||||||||||||
| //Loading from an image drawable | ||||||||||||||||||||
| ivDrawable.load(R.drawable.placeholder_img) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Loading from a file | ||||||||||||||||||||
| ivFile.load(File("/path/to/some_image_placeholder.png")) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| //adding placeholder to loading images | ||||||||||||||||||||
| ivUrl.load("https://via.placeholder.com/600/92c952") { | ||||||||||||||||||||
| placeholder(R.drawable.placeholder_img) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| //applying some basic transformations to image using coil | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ivUrl.load("https://via.placeholder.com/600/92c952") { | ||||||||||||||||||||
| transformations(CircleCropTransformation()) // Crops and centres the image into a circle. | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ivUrl.load("https://via.placeholder.com/600/92c952") { | ||||||||||||||||||||
| transformations(BlurTransformation(requireContext())) // Applies a Gaussian Blur. | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ivUrl.load("https://via.placeholder.com/600/92c952") { | ||||||||||||||||||||
| transformations(GrayscaleTransformation()) // Shades the image into grayscale. | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ivUrl.load("https://via.placeholder.com/600/92c952") { | ||||||||||||||||||||
| transformations(RoundedCornersTransformation()) // Crops the image to fit the target's dimensions and rounds the corners of the image. | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| } | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,28 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| tools:context=".CoilFragment"> | ||
|
|
||
|
|
||
| <TextView | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:text="@string/hello_blank_fragment" /> | ||
|
|
||
| </FrameLayout> | ||
| <ImageView | ||
| android:layout_width="150dp" | ||
| android:layout_height="150dp" | ||
| android:layout_above="@id/ivDrawable" | ||
| android:layout_centerHorizontal="true" | ||
| android:layout_marginBottom="15dp" | ||
| android:id="@+id/ivFile" /> | ||
| <ImageView | ||
| android:layout_width="150dp" | ||
| android:layout_height="150dp" | ||
| android:layout_alignParentEnd="true" | ||
| android:layout_marginEnd="50dp" | ||
| android:layout_centerVertical="true" | ||
| android:id="@+id/ivUrl" /> | ||
| <ImageView | ||
| android:layout_centerVertical="true" | ||
| android:layout_width="150dp" | ||
| android:layout_height="150dp" | ||
| android:layout_marginStart="50dp" | ||
| android:id="@+id/ivDrawable" /> | ||
| </RelativeLayout> |
Uh oh!
There was an error while loading. Please reload this page.