Struct droid_wrap::android::widget::LinearLayout

source ·
pub struct LinearLayout { /* private fields */ }
Expand description
  • 将其他视图水平排列在一列中或垂直排列在一行中的布局。
  • 以下代码片段展示了如何在布局 XML 文件中包含线性布局:
  • <LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android
  • android:layout_width="match_parent"
  • android:layout_height="match_parent"
  • android:paddingLeft="16dp"
  • android:paddingRight="16dp"
  • android:orientation="horizontal"
  • android:gravity="center"&gt;
  • &lt;!-- 在此处添加其他小部件或布局标签.这些标签被视为线性布局的 "子视图" "子项" --&gt;
  • </LinearLayout>
  • 设置 android:orientation 以指定子视图是否显示在行或列中。要控制线性布局如何对齐其包含的所有视图,请为 android:gravity 设置一个值。例如,上面的代码片段将 android:gravity 设置为 “center”。
  • 您设置的值会影响单行或单列内所有子视图的水平和垂直对齐。您可以在各个子视图上设置 android:layout_weight 以指定线性布局如何在其包含的视图之间划分剩余空间。有关示例,请参阅线性布局指南。请参阅 LinearLayout.LayoutParams 以了解您可以在子视图上设置的其他属性,以影响其在包含的线性布局中的位置和大小。

Implementations§

source§

impl LinearLayout

source

pub fn set_orientation(&self, orientation: i32)

  • 布局应该是一列还是一行。
  • orientation 传递水平或垂直。默认值为水平。
source

pub fn get_orientation(&self) -> i32

  • 返回当前方向。
  • 返回:水平或垂直

Methods from Deref<Target = ViewGroup>§

source

pub fn add_view(&self, child: &View)

  • 添加子视图。如果子视图上尚未设置布局参数,则此 ViewGroup 的默认参数将设置在该子视图上。
  • 注意:不要从 draw(Canvas)、onDraw(Canvas)、dispatchDraw(Canvas) 或任何相关方法调用此方法。
  • child 要添加的子视图
source

pub fn remove_all_views(&self)

  • 调用此方法可从 ViewGroup 中删除所有子视图。
  • 注意:不要从 draw(Canvas)、onDraw(Canvas)、dispatchDraw(Canvas) 或任何相关方法调用此方法。
source

pub fn remove_all_views_in_layout(&self)

当 ViewGroup 子类必须先知道其在屏幕上的大小,然后才能计算要渲染的子视图数量时,此方法会由 ViewGroup 子类调用,以从自身移除子视图。例如 Gallery 或 ListView,它们可能“有”50 个子视图,但实际上只渲染当前可容纳在屏幕上的对象内的子视图数量。除非您正在扩展 ViewGroup 并了解视图测量和布局管道,否则请不要调用此方法。 注意:不要从 draw(Canvas)、onDraw(Canvas)、dispatchDraw(Canvas) 或任何相关方法调用此方法。

Methods from Deref<Target = View>§

source

pub const NO_ID: i32 = -1i32

source

pub const LAST_APP_AUTOFILL_ID: i32 = 1_073_741_823i32

source

pub const VISIBLE: i32 = 0i32

source

pub const INVISIBLE: i32 = 4i32

source

pub const GONE: i32 = 8i32

source

pub fn announce_for_accessibility<CS: CharSequence>(&self, text: &CS)

  • 发送 AccessibilityEvent 的便捷方法。TYPE_ANNOUNCEMENT AccessibilityEvent 建议无障碍服务向其用户宣布指定的文本。
  • 注意:使用此 API 生成的事件不具有语义含义,仅适用于特殊情况。应用通常可以通过准确提供其 UI 的语义来实现正确的无障碍行为。它们不需要指定向用户宣布的具体内容。一般来说,只宣布转换,不要为按钮按下等简单操作生成确认消息。相反,请简明扼要地标记控件,对于重大的 UI 更改(如窗口更改),请使用 android.app.Activity.setTitle(CharSequence) 和 setAccessibilityPaneTitle(CharSequence)。使用 setAccessibilityLiveRegion(int) 通知用户用户界面内关键视图的更改。这些仍应谨慎使用,因为它们可能会在每次更新视图时生成通知。
  • text 通知文本。
source

pub fn get_width(&self) -> i32

  • 返回视图的宽度。
  • 返回:视图的宽度(以像素为单位)。
source

pub fn get_height(&self) -> i32

  • 返回视图的高度。
  • 返回:视图的高度(以像素为单位)。
source

pub fn request_focus(&self) -> bool

  • 调用此操作可以尝试将焦点集中到特定视图或其子视图之一。如果视图不可聚焦(isFocusable返回false),或者由于其他条件而无法聚焦(当设备处于触摸模式、不可见、未启用或没有大小时,在触摸模式下无法聚焦(isForusableInTouchMode)),则视图实际上不会聚焦。另请参阅focusSearch(int),这是用来表示有焦点,并希望视图的父母寻找下一个焦点的方法。这相当于用参数FOCUS_DOWN和null调用requestFocus(int, Rect)。
  • 返回:这个视图或它的一个后代是否真的成为焦点。
source

pub fn clear_focus(&self)

  • 当此视图想要放弃焦点时调用。如果焦点被清除,则调用 onFocusChanged(boolean, int, Rect)。
  • 注意:当不处于触摸模式时,框架将在焦点清除后尝试将焦点放在从顶部开始的第一个可聚焦视图上。因此,如果此视图是从顶部开始的第一个可获得焦点的视图,则将调用与清除焦点相关的所有回调,之后框架将焦点放在此视图上。
source

pub fn find_focus(&self) -> Option<Self>

  • 在以此视图为根的层次结构中查找当前具有焦点的视图。
  • 返回:当前具有焦点的视图,如果找不到焦点视图,则返回 null。
source

pub fn is_activated(&self) -> bool

  • 指示此视图的激活状态。
  • 返回:如果视图已激活,则返回 true,否则返回 false
source

pub fn set_activated(&self, activated: bool)

  • 更改此视图的激活状态。视图可以激活也可以不激活。请注意,激活与选择不同。选择是一种瞬时属性,表示用户当前正在与之交互的视图(层次结构)。激活是一种长期状态,用户可以将视图移入或移出。例如,在启用单选或多选的列表视图中,当前选择集中的视图处于激活状态。(嗯,是的,我们对这里的术语深感抱歉。)激活状态会向下传播到设置该状态的视图的子级。
  • activated 如果必须激活视图,则为 true,否则为 false
source

pub fn get_x(&self) -> f32

  • 此视图的可视 x 位置(以像素为单位)。这相当于 TranslationX 属性加上当前 Left 属性。
  • 返回:此视图的可视 x 位置(以像素为单位)。
source

pub fn set_x(&self, x: f32)

  • 设置此视图的可视 x 位置(以像素为单位)。这相当于将 TranslationX 属性设置为传入的 x 值与当前 left 属性之间的差值。
  • x 此视图的可视 x 位置(以像素为单位)。
source

pub fn get_y(&self) -> f32

  • 此视图的视觉 y 位置(以像素为单位)。这相当于 TranslationY 属性加上当前的 Top 属性。
  • 返回:此视图的视觉 y 位置(以像素为单位)。
source

pub fn set_y(&self, y: f32)

  • 设置此视图的视觉 y 位置(以像素为单位)。这相当于将 TranslationY 属性设置为传入的 y 值与当前 top 属性之间的差值。
  • y 此视图的视觉 y 位置(以像素为单位)。
source

pub fn find_view_by_id(&self, id: i32) -> Option<Self>

  • 查找具有给定 ID 的第一个后代视图,如果 ID 与 getId() 匹配,则查找视图本身,如果 ID 无效 (< 0) 或层次结构中没有匹配的视图,则返回 null。
  • 注意:在大多数情况下 - 取决于编译器支持 - 生成的视图会自动转换为目标类类型。如果目标类类型不受约束,则可能需要显式转换。
  • 返回:如果找到,则返回具有给定 ID 的视图,否则返回 null
  • id 要搜索的 ID
source

pub fn get_content_description<CS: CharSequence>(&self) -> Option<CS>

  • 返回视图的内容描述。
  • 注意:不要覆盖此方法,因为它不会影响呈现给无障碍服务的内容描述。您必须调用 setContentDescription(CharSequence) 来修改内容描述。
  • 返回:内容描述
source

pub fn set_content_description<CS: CharSequence>( &self, content_description: Option<CS>, )

  • 设置视图的内容描述。内容描述简要描述视图,主要用于辅助功能支持,以确定应如何向用户呈现视图。对于没有文本表示的视图(如 android.widget.ImageButton),有用的内容描述会解释视图的作用。例如,用于拨打电话的带有电话图标的图像按钮可以使用“呼叫”作为其内容描述。用于保存文件的软盘图像可以使用“保存”。这应该省略角色或状态。角色是指视图的用户界面元素类型,例如按钮或复选框。状态是指视图经常变化的属性,例如按钮的开/关状态或音量滑块的音频级别。内容描述更新并不频繁,并且在元素的语义内容(而不是状态)发生变化时使用。例如,在音乐播放期间,播放按钮可能会更改为暂停按钮。
  • content_description 内容描述。
source

pub fn set_id(&self, id: i32)

  • 设置此视图的标识符。标识符在此视图的层次结构中不必唯一。标识符应为正数。
  • id 用于标识视图的数字
source

pub fn get_id(&self) -> i32

  • 返回此视图的标识符。
  • 返回:用于标识视图的正整数,如果视图没有 ID,则返回 NO_ID
source

pub fn set_on_click_listener<L: View_OnClickListener + JProxy>(&self, l: &L)

  • 单击此视图时注册要调用的回调。如果此视图不可点击,则将设为可点击。
  • l 将运行的回调
source

pub fn set_on_long_click_listener<L: View_OnLongClickListener + JProxy>( &self, l: &L, )

  • 注册一个回调,当此视图被点击并按住时调用。如果此视图不是长按可点击的,则变为长按可点击的。
  • l 将运行的回调
source

pub fn get_layout_params(&self) -> Option<ViewGroup_LayoutParams>

  • 获取与此视图关联的 LayoutParams。所有视图都应具有布局参数。这些参数为此视图的父级提供参数,指定应如何排列。
  • ViewGroup.LayoutParams 有许多子类,这些子类对应于负责排列其子级的 ViewGroup 的不同子类。如果此视图未附加到父 ViewGroup 或 setLayoutParams(ViewGroup.LayoutParams) 未成功调用,则此方法可能返回 null。当视图附加到父 ViewGroup 时,此方法不得返回 null。
  • 返回:与此视图关联的 LayoutParams,如果尚未设置参数,则返回 null
source

pub fn set_layout_params(&self, params: &ViewGroup_LayoutParams)

  • 设置与此视图相关的布局参数。这些参数为该视图的父级提供参数,指定应如何排列。ViewGroup 有许多子类。LayoutParams,这些对应于负责排列其子级的 ViewGroup 的不同子类。
  • params 此视图的布局参数,不能为空
source

pub fn set_visibility(&self, visibility: i32)

  • 设置此视图的可见性状态。
  • visibility VISIBLE、INVISIBLE 或 GONE 之一。
source

pub fn get_visibility(&self) -> i32

  • 返回此视图的可见性状态。
  • 返回:VISIBLE、INVISIBLE 或 GONE 之一。
source

pub fn perform_click(&self) -> bool

  • 如果已定义,则调用此视图的 OnClickListener。执行与点击相关的所有常规操作:报告可访问性事件、播放声音等。
  • 返回:如果已分配一个被调用的 OnClickListener,则返回 True,否则返回 false。
source

pub fn is_clickable(&self) -> bool

  • 指示此视图是否对点击事件作出反应。如果视图可点击,则返回 true,否则返回 false
source

pub fn set_clickable(&self, clickable: bool)

  • 启用或禁用此视图的点击事件。当视图可点击时,每次点击时它的状态都会更改为“按下”。子类应将视图设置为可点击,以便对用户的点击做出视觉反应。
  • clickable true 表示视图可点击,否则为 false
source

pub fn set_allow_click_when_disabled(&self, clickable_when_disabled: bool)

  • 禁用时启用或禁用此视图的单击事件。
  • clickable_when_disabled true使视图可单击,否则为false
source

pub fn is_long_clickable(&self) -> bool

  • 指示此视图是否对长按事件作出反应。
  • 返回:如果视图可长按,则返回 true,否则返回 false
source

pub fn set_long_clickable(&self, long_clickable: bool)

  • 启用或禁用此视图的长按事件。当视图可长按时,它会对用户按住按钮的时间长于点击做出反应。此事件可以启动侦听器或上下文菜单。
  • long_clickable true 表示视图可长按,否则为 false
source

pub fn is_context_clickable(&self) -> bool

  • 指示此视图是否对上下文点击反应。
  • 返回:如果视图是上下文可单击的,则为false,否则否则
source

pub fn set_context_clickable(&self, context_clickable: bool)

  • 启用或禁用此视图的上下文点击。此事件可以启动侦听器。
  • context_clickable true 表示使视图对上下文点击做出反应,否则为 false
source

pub fn has_on_click_listeners(&self) -> bool

  • 返回此视图是否具有附加的 OnClickListener。如果有侦听器,则返回 true,如果没有,则返回 false。
source

pub fn has_on_long_click_listeners(&self) -> bool

  • 返回此视图是否具有附加的 OnLongClickListener。如果有侦听器,则返回 true,如果没有,则返回 false。
source

pub fn get_keep_screen_on(&self) -> bool

  • 返回屏幕是否应保持开启,对应于 KEEP_SCREEN_ON 的当前值。
  • 返回:如果设置了 KEEP_SCREEN_ON,则返回 true。
source

pub fn get_parent<VP: ViewParent>(&self) -> Option<VP>

  • 获取此视图的父级。请注意,父级是 ViewParent,不一定是 View。
  • 返回:此视图的父级。
source

pub fn set_on_key_listener<L: View_OnKeyListener>(&self, l: &L)

  • 注册一个回调,当此视图中按下硬件键时调用该回调。软件输入法中的按键通常不会触发此侦听器的方法。
  • l 要附加到此视图的按键侦听器
source

pub fn has_ime_focus(&self) -> bool

如果此视图位于当前具有 IME 可聚焦状态的窗口中,则为 true。

source

pub fn has_nested_scrolling_parent(&self) -> bool

  • 如果此视图具有嵌套滚动父级,则返回 true。
  • 嵌套滚动父级的存在表明此视图已启动嵌套滚动,并且已被视图层次结构中更高层次的祖先视图接受。
  • 返回:此视图是否具有嵌套滚动父级
source

pub fn get_tooltip<CS: CharSequence>(&self) -> Option<CS>

二进制兼容性存根。当我们最终完成 O API 时将被删除。

source

pub fn get_tooltip_text<CS: CharSequence>(&self) -> Option<CS>

  • 返回视图的工具提示文本。
  • 注意:不要重写此方法,因为它不会影响工具提示中显示的文本。您必须调用 setTooltipText(CharSequence) 来修改工具提示文本。
  • 返回:工具提示文本
source

pub fn set_tooltip<CS: CharSequence>(&self, tooltip_text: Option<CS>)

二进制兼容性存根。当我们最终完成 O API 时将被删除。

source

pub fn set_tooltip_text<CS: CharSequence>(&self, tooltip_text: Option<CS>)

  • 设置工具提示文本,该文本将显示在视图旁边的小弹出窗口中。工具提示将显示在:
  • 长按时,除非另有处理(通过 OnLongClickListener 或上下文菜单)。
  • 悬停时,在指针停止移动后的短暂延迟后
  • 注意:不要覆盖此方法,因为它不会影响工具提示中显示的文本。
  • tooltip_text 工具提示文本,如果不需要工具提示,则为 null。

Methods from Deref<Target = GlobalRef>§

source

pub fn as_obj(&self) -> &JObject<'static>

Get the object from the global ref

This borrows the ref and prevents it from being dropped as long as the JObject sticks around.

Methods from Deref<Target = JObject<'static>>§

source

pub fn as_raw(&self) -> *mut _jobject

Returns the raw JNI pointer.

Trait Implementations§

source§

impl Debug for LinearLayout

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for LinearLayout

§

type Target = ViewGroup

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl From<&GlobalRef> for LinearLayout

source§

fn from(obj: &GlobalRef) -> Self

Converts to this type from the input type.
source§

impl Into<GlobalRef> for &LinearLayout

source§

fn into(self) -> GlobalRef

Converts this type into the (usually inferred) input type.
source§

impl JObjNew for LinearLayout

§

type Fields = ()

字段类型
source§

fn _new(this: &GlobalRef, fields: Self::Fields) -> Self

从java对象创建本地对象。 this java对象引用。
source§

fn null() -> Self
where Self: Sized, Self::Fields: Default,

创建空对象。
source§

impl JObjRef for LinearLayout

source§

fn java_ref(&self) -> GlobalRef

获取java对象引用。
source§

impl JType for LinearLayout

§

type Error = Error

错误类型。
source§

const CLASS: &'static str = "android/widget/LinearLayout"

java类的名称。
source§

const OBJECT_SIG: &'static str = "Landroid/widget/LinearLayout;"

对象的签名描述。
source§

impl PartialEq for LinearLayout

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToString for LinearLayout

source§

fn to_string(&self) -> String

Converts the given value to a String. Read more

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>,

§

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>,

§

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.