بنام خود خدا
بطور کلی در پروژههای اندروید هر چیزی که کد نیست، یعنی فایلهای ثابت رابط کاربری یا تنظیمات اپ (مثل رنگ، تصویر، استایل، متن و غیره)، بهعنوان Resource (منبع) در فولدر res/ نگهداری میشه.
app/
└── src/
└── main/
├── java/... ← فایلهای کد
├── res/ ← منابع (Resources)
│ ├── drawable/ ← تصاویر و پسزمینهها
│ ├── layout/ ← فایلهای رابط کاربری XML
│ ├── values/ ← رنگها، استایلها، رشتهها و...
│ ├── mipmap/ ← آیکونهای اپلیکیشن
│ ├── menu/ ← منوی اپ
│ ├── anim/ ← انیمیشنها
│ └── xml/ ← تنظیمات خاصتر (مثل preferences)
drawable/برای تعریف گرافیکها، پسزمینهها، شکلها و افکتها در XML (بدون نیاز به تصویر PNG/JPG).
shape رسم اشکال ساده (مستطیل، دایره، گوشه گرد)
background_shape.xml selector انتخاب حالتهای مختلف (مثلاً فشار دادن، فوکوس، نرمال)
button_selector.xml layer-list چند پسزمینه روی هم
layer_bg.xml ripple افکت کلیک مدرن (API 21+)
ripple_bg.xml inset / scale / rotate / clip تغییر ابعاد یا موقعیت drawable پوشش و جلوههای دلخواه
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/purple_200"/> <corners android:radius="12dp"/> <padding android:left="8dp" android:right="8dp"/> </shape>
🔹 استفاده:
android:background="@drawable/rounded_bg"
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/teal_700" android:state_pressed="true"/> <item android:drawable="@color/purple_200"/> </selector>
🔹 در حالت کلیک → سبز تیره
🔹 در حالت معمولی → بنفش روشن
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?attr/colorControlHighlight"> <item android:drawable="@color/purple_200"/> </ripple>
4️⃣ layer-list (چند لایه پشتسرهم)
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/purple_200"/>
<item android:drawable="@drawable/rounded_border"/>
</layer-list>
values/حاوی فایلهای XML تعریف مقادیر ثابت مثل رنگها، رشتهها، ابعاد و استایلها است.
colors.xml تعریف رنگها
<color name="purple_200">#BB86FC</color>
strings.xml تعریف متنهای ثابت
<string name="app_name">MyApp</string>
dimens.xml تعریف اندازهها
<dimen name="padding_small">8dp</dimen>
styles.xml ساخت استایل کلی Themeها و استایلهای ویو
themes.xml از Android 10+ برای تعریف تمها و MaterialTheme
layout/در اینجا فایلهای رابط کاربری (UI) اپ رو میسازی.
هر فایل یک Activity یا Fragment یا Component رو نمایش میده.
📄 مثال:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="16dp" android:background="@drawable/ripple_bg"> <TextView android:id="@+id/txt_hello" android:text="@string/hello_world" android:textSize="@dimen/text_large" android:textColor="@color/black"/> </LinearLayout>
mipmap/برای ذخیره آیکونهای اپلیکیشن (در اندازههای مختلف).
🧠 تفاوت با drawable: فقط برای آیکونها بهینهسازی شده (automatic scaling در لانچر).
menu/تعریف منوهای OptionMenu یا ContextMenu در XML.
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/action_settings" android:title="@string/settings" android:icon="@drawable/ic_settings"/> </menu>
anim/ و animator/برای تعریف انیمیشنهای حرکتی (ترجمه، چرخش، شفافیت، مقیاس و …).
<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500" />
xml/برای تعریف تنظیمات خاصه مثل:
Preference screens
File provider paths
Backup rules
مثلاً res/xml/file_paths.xml:
<external-files-path name="my_images" path="pictures/" /> </paths>