pub struct HorizontalScrollView { /* private fields */ }Expand description
A HorizontalScrollView provides horizontal scrolling for content
§Important Usage Notes for TabLayout
When using HorizontalScrollView with TabLayout for page switching:
- Use pixel units: Page widths must be set using
set_width_px(), notset_width() - Match dimensions: Use
get_dimensions()to get screen width, then set each page width to match - Scroll position: Calculate scroll position as
page_width * tab_index
§Example
// Create HorizontalScrollView with snapping and no scrollbar
let scroll = activity.create_horizontal_scroll_view_with_params(
Some(root_id), true, true, true
)?;
// Get width in pixels
let (page_width, _) = scroll.view().get_dimensions(activity)?;
// Create pages with pixel-based width
let page1 = activity.create_linear_layout(Some(content_id))?;
page1.view().set_width_px(activity, page_width)?; // Use px, not dp!
// Scroll to page 2
scroll.set_scroll_position(activity, page_width * 2, 0, true)?;Implementations§
Source§impl HorizontalScrollView
impl HorizontalScrollView
Sourcepub fn new(activity: &mut Activity, parent: Option<i64>) -> Result<Self>
pub fn new(activity: &mut Activity, parent: Option<i64>) -> Result<Self>
Create a new HorizontalScrollView
Sourcepub fn new_with_params(
activity: &mut Activity,
parent: Option<i64>,
fillviewport: bool,
snapping: bool,
nobar: bool,
) -> Result<Self>
pub fn new_with_params( activity: &mut Activity, parent: Option<i64>, fillviewport: bool, snapping: bool, nobar: bool, ) -> Result<Self>
Create a new HorizontalScrollView with custom parameters
Sourcepub fn get_scroll_position(&self, activity: &mut Activity) -> Result<(i32, i32)>
pub fn get_scroll_position(&self, activity: &mut Activity) -> Result<(i32, i32)>
Get the scroll position (x, y) in pixels
Sourcepub fn set_scroll_position(
&self,
activity: &mut Activity,
x: i32,
y: i32,
smooth: bool,
) -> Result<()>
pub fn set_scroll_position( &self, activity: &mut Activity, x: i32, y: i32, smooth: bool, ) -> Result<()>
Set the scroll position
§Arguments
x- Horizontal scroll position in pixelsy- Vertical scroll position in pixels (usually 0 for HorizontalScrollView)smooth- Whether to scroll smoothly or jump immediately
Auto Trait Implementations§
impl Freeze for HorizontalScrollView
impl RefUnwindSafe for HorizontalScrollView
impl Send for HorizontalScrollView
impl Sync for HorizontalScrollView
impl Unpin for HorizontalScrollView
impl UnwindSafe for HorizontalScrollView
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more