Android UI & Preferences Notes
1. Defining Preferences in XML
Preferences are defined in res/xml/ using . Example: EditTextPreference, CheckBoxPreference.
2. Location of Preference XML Files
Typically in res/xml/ directory.
3. Setting Up an AVD
Steps: Tools → Device Manager → Create Virtual Device → Select Hardware & System Image →
Configure → Finish.
4. AVD Features & Configurations
Device type, system image, RAM, storage, screen resolution, sensors, orientation, graphics.
5. Layout Resources
Defined in res/layout/. Separate UI design from logic. Support multiple screen sizes.
6. Example Layout
- defines a simple Hello World UI.
7. Running App on Emulator
Build project → Run → Select AVD → Gradle builds → App launches.
8. Form Widgets
Examples: EditText, Button, CheckBox, RadioButton, Spinner, Switch.
9. Types of Layouts
LinearLayout, RelativeLayout/ConstraintLayout, FrameLayout, TableLayout, GridLayout,
CoordinatorLayout.
10. dp vs px
dp = density-independent pixels, recommended for UI. px = physical pixels, rarely used.
11. sp for Text Size
sp = scale-independent pixels, respects user font settings, used for text.
12. Shared Preferences
Key-value storage for small data. Example: prefs.edit().putString().apply(); prefs.getString().
13. Shared Preferences vs Others
Preferences = small settings; Internal = private files; External = shared files; SQLite = structured
data; Providers = shared across apps.
14. Layout Types Recap
LinearLayout = forms, ConstraintLayout = complex UIs, FrameLayout = overlays, Table/GridLayout
= tabular data.