Expand description
Base View type and common view operations
§Important Notes on Dimensions and Units
Android uses two different units for View dimensions:
- dp (density-independent pixels): Default unit, scales with screen density
- px (pixels): Actual screen pixels
§Critical for TabLayout/ScrollView
When working with HorizontalScrollView or TabLayout:
get_dimensions()returns values in pixels (px)set_width()andset_height()use dp by default- You must use
set_width_px()andset_height_px()to match dimensions!
§Example
// Get dimensions (returns pixels)
let (width_px, height_px) = scroll_view.view().get_dimensions(activity)?;
// WRONG: This uses dp, not px!
// page.view().set_width(activity, width_px)?; // Width mismatch!
// CORRECT: Use set_width_px to match pixel values
page.view().set_width_px(activity, width_px)?; // Perfect match!Structs§
- View
- Base View structure
Constants§
- MATCH_
PARENT - Special dimension constants for Android layouts
- WRAP_
CONTENT