इस page में हम Android के resources, R.java, assets, layouts, और drawable resources को समझेंगे.
Android app में resources (layouts, images, strings, colors, आदि) का उपयोग करके UI को बेहतर और dynamic बनाया जाता है।
Android में resources (res/) वह सभी static content होते हैं, जो app के UI और functionality को define करने में मदद करते हैं। ये files hardcoded values को हटाकर ऐप को flexible, scalable, और multi-language supportive बनाती हैं।
उदाहरण के लिए:
सभी Resources res/ folder में store किए जाते हैं और R.java फाइल के जरिए इन्हें code में access किया जाता है।
Resource Type | Location | Description |
---|---|---|
Drawable | res/drawable/ | Images, XML graphics (icons, buttons) |
Layout | res/layout/ | XML UI files (Activity, Fragments) |
Mipmap | res/mipmap | App launcher icons (Adaaptive icons) |
Values | res/values/ | Strings, colors, dimensions, themes |
Raw | res/raw/ | Audio, videos, JSON, other raw files |
XML | res/xml/ | XML-based configurations |
R.java एक ऑटो-जेनरेटेड जावा फाइल होती है, जो सभी resources का unique identifier (ID) स्टोर करती है।
जब भी आप किसी resource को res/ फ़ोल्डर में एड करते हैं, Android Studio उसे R.java फाइल में एक unique ID के रूप में स्टोर करता है। फिर आप उस resource को कोड में आसानी से access कर सकते हैं।
Example: R.java का उपयोग
int color = getResources().getColor(R.color.primary_color); // Colors String appName = getString(R.string.app_name); // Strings imageView.setImageResource(R.drawable.logo); // Drawables
Example: R.java की Structure
public final class R { public static final class drawable { public static final int logo = 0x7f010000; } public static final class layout { public static final int activity_main = 0x7f020000; } public static final class string { public static final int app_name = 0x7f030000; } }
Note: यह फ़ाइल manually edit नहीं की जाती। यह automatically generate होती है।
Android में assets/ folder एक raw file storage location है, जहाँ आप वे files रख सकते हैं जो res/ folder में सीधे store नहीं की जा सकतीं, जैसे कि:
Android का resources system (res/ फ़ोल्डर) assets को directly access नहीं कर सकता। इसके बजाय, हमें AssetManager API का उपयोग करके assets को load करना पड़ता है।
Android में layouts XML files के रूप में store होती हैं, जो UI structure को define करती हैं। ये res/layout/ folder में मिलती हैं।
Layout Types | Description |
---|---|
LinearLayout | Elements को vertical या horizontal में arrange करता है |
RelativeLayout | Views को एक-दूसरे के relation में set करता है |
ConstraintLayout | Flexible & optimized layout |
FrameLayout | Single child element का उपयोग |
GridLayout | Grid-based structure |
TableLayout | Rows और Columns में divide |
Drawable resources वे graphics होते हैं जिन्हें Android app में UI elements के रूप में उपयोग किया जाता है। ये res/drawable/ folder में store किए जाते हैं और विभिन्न प्रकार के होते हैं।
हैलो दोस्तों! उम्मीद करता हूं आपको हमारा यह कंटेंट पसंद आया होगा। अगर आपको हमारा ये content/post पसंद आई हो तो अपने दोस्तों के पास भी share करे। और अगर आपको कोई problem या कोई specific content हिन्दी में चाहिए है तो आप हमें नीचे दिए गए Email या whatsapp number के जरिए बता सकते है।
अगर आप CCC/diploma/polytechnic/MCA/BCA etc कर रहे है तो ये website स्पेशली आपके लिए ही है, जो student हिंदी में पढ़ाई करते है।
Email: deepanshuranjan8057@gmail.com
Whatsapp: +91 8057754706