CircularImageView लाइब्रेरी का उपयोग करके गोलाकार इमेज बनाना
Android में डिफ़ॉल्ट रूप से ImageView आयताकार होता है। गोलाकार इमेज (प्रोफाइल पिक्चर आदि) बनाने के लिए हम लोकप्रिय लाइब्रेरी CircularImageView का उपयोग कर सकते हैं।
निर्भरता जोड़ें
अपने build.gradle (Module: app) में निम्नलिखित निर्भरता जोड़ें:
dependencies {
implementation 'com.mikhaellopez:circularimageview:3.2.0'
// अन्य निर्भरताएं...
}
लेआउट में CircularImageView का उपयोग करें
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:app="https://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<com.mikhaellopez.circularimageview.CircularImageView
android:id="@+id/circularImageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/profile_image"
app:civ_border_color="#FFFFFF"
app:civ_border_width="4dp"
app:civ_shadow="true"
app:civ_shadow_radius="10"
app:civ_shadow_color="#8BC34A" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="उपयोगकर्ता नाम"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
मुख्य XML एट्रिब्यूट्स (Properties)
| एट्रिब्यूट | विवरण | डिफ़ॉल्ट मान |
|---|---|---|
| app:civ_border | बॉर्डर सक्षम/अक्षम करें | true |
| app:civ_border_color | बॉर्डर का रंग | सफेद |
| app:civ_border_width | बॉर्डर की चौड़ाई | 4dp |
| app:civ_background_color | बैकग्राउंड रंग | सफेद |
| app:civ_shadow | छाया सक्षम करें | false |
| app:civ_shadow_color | छाया का रंग | काला |
| app:civ_shadow_radius | छाया की त्रिज्या | 8.0f |
| app:civ_shadow_gravity | छाया की दिशा | bottom |
प्रोग्रामेटिक रूप से कॉन्फ़िगर करना
CircularImageView civ = findViewById(R.id.circularImageView);
civ.setBorderColor(Color.WHITE);
civ.setBorderWidth(4f);
civ.setShadowEnable(true);
civ.setShadowRadius(10f);
civ.setShadowColor(Color.parseColor("#8BC34A"));
civ.setImageResource(R.drawable.profile_image);
नोट
- लाइब्रेरी स्वचालित रूप से इमेज को गोलाकार क्रॉप करती है।
- GIF एनिमेशन भी सपोर्ट करता है।
- AndroidX के साथ संगत।