HorizontalScrollView

Struct HorizontalScrollView 

Source
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:

  1. Use pixel units: Page widths must be set using set_width_px(), not set_width()
  2. Match dimensions: Use get_dimensions() to get screen width, then set each page width to match
  3. 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

Source

pub fn new(activity: &mut Activity, parent: Option<i64>) -> Result<Self>

Create a new HorizontalScrollView

Source

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

Source

pub fn id(&self) -> i64

Get the view ID

Source

pub fn view(&self) -> &View

Get the underlying View

Source

pub fn get_scroll_position(&self, activity: &mut Activity) -> Result<(i32, i32)>

Get the scroll position (x, y) in pixels

Source

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 pixels
  • y - Vertical scroll position in pixels (usually 0 for HorizontalScrollView)
  • smooth - Whether to scroll smoothly or jump immediately

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V