Android Widget Attributes——View

最近因为想着重新把这个插件捡起来,把view的属性慢慢的全部补上,所以顺便了解一下各个属性,在这里列举View的属性,含义,以及代码设置。

简书Markdown编辑器实在是渣,只能把表格换成下面这种形式

  • android:id
void setId(int);

设置id,单个布局中保持唯一。
可以用View.generateViewId()来生成。


  • android:accessibilityLiveRegion
void setAccessibilityLiveRegion(int);

辅助功能,在该视图更改时是否应通知用户。
View.ACCESSIBILITY_LIVE_REGION_NONE(xml:none)不通知;
View.ACCESSIBILITY_LIVE_REGION_POLITE(xml:polite)通知;
View.ACCESSIBILITY_LIVE_REGION_ASSERTIVE(xml:assertive)打断语音,并通知;


  • android:accessibilityTraversalAfter
void setAccessibilityTraversalAfter(int);

辅助功能,设置在辅助功能遍历中访问此视图的视图的ID。
屏幕阅读器必须在此视图的内容之前访问另一视图的内容。
(反正我没看懂)


  • android:accessibilityTraversalBefore
void setAccessibilityTraversalBefore(int);

辅助功能,设置在辅助功能遍历中访问此视图的视图的ID。
屏幕阅读器必须在此视图的内容之前访问此视图的内容。
(这个也没看懂)


  • android:alpha
void setAlpha(float);

透明度,值在0-1之间。
0为透明,1为不透明。


  • android:autofillHints
void setAutofillHints(String...);

自动填充各种信息
View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE(xml:creditCardExpirationDate)信用卡到期日期;
View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY(xml:creditCardExpirationDay)信用卡到期日;
View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH(xml:creditCardExpirationMonth)信用卡到期月;
View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR(xml:creditCardExpirationYear)信用卡到期年;
View.AUTOFILL_HINT_CREDIT_CARD_NUMBER(xml:creditCardNumber)信用卡卡号;
View.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE(xml:creditCardSecurityCode)信用卡安全密码;
View.AUTOFILL_HINT_EMAIL_ADDRESS(xml:emailAddress)邮箱地址
View.AUTOFILL_HINT_NAME(xml:name)用户真名;
View.AUTOFILL_HINT_PASSWORD(xml:password)用户密码;
View.AUTOFILL_HINT_PHONE(xml:phone)电话号码;
View.AUTOFILL_HINT_POSTAL_ADDRESS(xml:postalAddress)邮寄地址;
View.AUTOFILL_HINT_POSTAL_CODE(xml:postalCode)邮寄编号;
View.AUTOFILL_HINT_USERNAME(xml:username)用户名;


  • android:background
void setBackgroundColor(int);
void setBackgroundResource(int);
void setBackgroundDrawable(Drawable);
void setBackground(Drawable);//api 16

view的背景,可以使用颜色图片等。


  • android:backgroundTint
void setBackgroundTintList(ColorStateList);

将设置的颜色和原来的背景进行一个叠加。
根据backgroundTintMode来叠加。


  • android:backgroundTintMode
void setBackgroundTintMode(PorterDuff.Mode);

背景叠加模式PorterDuff.Mode


  • android:clickable
void setClickable(boolean);

是否可点击


  • android:contentDescription
void setContentDescription(CharSequence);

对于一些视力有障碍的用户,无法理解这个控件是做什么的。
如果用户安装了辅助浏览工具比如TalkBack,这时用户点击这个控件,android系统会自动使用人声朗读控件android:contentDescription属性说指向的内容。
这样用户就可以知道这个控件是做什么用的。
这个属性的主要功能就是为视力有障碍的人增加对控件的解释。


  • android:contextClickable
void setContextClickable(boolean);

定义此视图是否对上下文单击事件作出反应。


  • android:defaultFocusHighlightEnabled
void setDefaultFocusHighlightEnabled(boolean);

在其背景中未定义R.attr.state_focused时,获得焦点时是否应使用默认焦点效果。


  • android:drawingCacheQuality
void setDrawingCacheQuality(int);

在启用绘图缓存时定义绘图缓存的质量。
默认值为auto。
随着API 11中硬件加速渲染,视图绘制缓存基本上已经过时,不推荐使用。
View.DRAWING_CACHE_QUALITY_LOW(xml:low)低质量;
View.DRAWING_CACHE_QUALITY_HIGH(xml:high)高质量;
View.DRAWING_CACHE_QUALITY_AUTO(xml:auto)自动;


  • android:duplicateParentState
void setDuplicateParentStateEnabled(boolean);

当此属性设置为true时,视图将从其直接父级而不是从其自身获取其可绘制状态(聚焦,按下等)。
如,点击父控件,子控件会有点击效果但是不触发点击事件。


  • android:elevation
void setElevation(float);

z轴的高度。


  • android:fadeScrollbars
void setScrollbarFadingEnabled(boolean);

在不使用时是否淡出滚动条。


  • android:fadingEdge
void setHorizontalFadingEdgeEnabled(boolean);
void setVerticalFadingEdgeEnabled(boolean);

api>=14被忽略,使用requiresFadingEdge代替


  • android:fadingEdgeLength
void setFadingEdgeLength(int);

设置边框渐变的长度。


  • android:filterTouchesWhenObscured
void setFilterTouchesWhenObscured(boolean);

指定当视图的窗口被另一个可见窗口遮挡时是否过滤触摸。
设置为true时,只要在视图窗口上方出现Toast,对话框或其他窗口,视图就不会接收到后续的触摸事件。


  • android:fitsSystemWindows
void setFitsSystemWindows(boolean);

用于根据系统窗口(如状态栏)调整视图布局。
如果为true,则调整此视图的填充以为系统窗口留出空间。
如果为false,状态栏等会遮挡住界面。仅在此视图处于非嵌入式Activity时才会生效。


  • android:focusable
void setFocusable(boolean);
void setFocusable(int);

控制视图是否可以获得焦点。
默认情况下,是auto,它允许框架确定用户是否可以将焦点移动到视图。
通过将此属性设置为true,允许视图获得焦点。
通过将其设置为false,视图将不会成为焦点。
此值不会影响直接调用View.requestFocus(),无论此视图如何,都会请求焦点。
只会影响焦点导航尝试移动焦点的位置。


  • android:focusableInTouchMode
void setFocusableInTouchMode(boolean);

用于控制视图在触摸模式下是否可以获得焦点。
如果为true,则该视图在单击时可以获得焦点,并且如果单击另一个没有将此属性设置为true的视图,则可以继续保持焦点。


  • android:focusedByDefault
void setFocusedByDefault(boolean);

此视图是否为默认焦点视图。
每个键盘导航集群只能有一个视图可以将此属性设置为true。


  • android:forceHasOverlappingRendering
void forceHasOverlappingRendering(boolean);

此视图是否具有在绘制时可能重叠的元素。
会覆盖hasOverlappingRendering()方法的返回值。


  • android:foreground
void setForeground(Drawable);

设置前景,可以做遮罩等。


  • android:foregroundGravity
void setForegroundGravity(int);

前景的Gravity。


  • android:foregroundTint
void setForegroundTintList(ColorStateList);

将设置的颜色和原来的前景进行一个叠加。
根据foregroundTintMode来叠加


  • android:foregroundTintMode
void setForegroundTintMode(PorterDuff.Mode);

前景叠加模式PorterDuff.Mode


  • android:hapticFeedbackEnabled
void setHapticFeedbackEnabled(boolean);

用于控制视图是否应为单击,长按等事件启用触觉反馈。


  • android:importantForAccessibility
void setImportantForAccessibility(int);

控制View是否能启用无障碍功能,辅助功能服务可能会忽略此属性并对视图树中的所有视图进行操作。
View.IMPORTANT_FOR_ACCESSIBILITY_AUTO(xml:auto)系统决定;
View.IMPORTANT_FOR_ACCESSIBILITY_YES(xml:yes)启用;
View.IMPORTANT_FOR_ACCESSIBILITY_NO(xml:no)不启用;
View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS(xml:noHideDescendants)不启用;


  • android:importantForAutofill
void setImportantForAutofill(int);

提示Android系统是否应将与此视图关联的视图节点包含在用于自动填充目的的视图结构中。
View.IMPORTANT_FOR_AUTOFILL_AUTO(xml:auto)系统决定;
View.IMPORTANT_FOR_AUTOFILL_YES(xml:yes)包含,并循环判断子控件;
View.IMPORTANT_FOR_AUTOFILL_NO(xml:no)不包含,并循环判断子控件;
View.IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS(xml:yesExcludeDescendants)包含,不判断子控件;
View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS(xml:noExcludeDescendants)不包含,不判断子控件;


  • android:isScrollContainer
void setScrollContainer(boolean);

如果视图将用作滚动容器,则设置此项,这意味着可以调整其大小以缩小其整个窗口,以便为输入方法提供空间。
如果未设置,当"scrollbars"设置了垂直滚动条,则默认值为true,否则为false。


  • android:keepScreenOn
void setKeepScreenOn(boolean);

控制屏幕常亮。


  • android:keyboardNavigationCluster
void setKeyboardNavigationCluster(boolean);

此视图是否是键盘导航集群的根节点(不太懂)。


  • android:labelFor
void setLabelFor(int);

指定视图的id,此视图用作可访问性标签。
例如,UI中EditText之前的TextView通常指定EditText中包含的信息。 因此,TextView是EditText的标签。


  • android:layerType
void setLayerType(int, Paint);

指定支持此视图的图层类型
默认值为none。
View.LAYER_TYPE_NONE(xml:none)不设置图层;
View.LAYER_TYPE_SOFTWARE(xml:software)使用软件图层;
View.LAYER_TYPE_HARDWARE(xml:hardware)使用硬件图层;


  • android:layoutDirection
void setLayoutDirection(int);

定义布局绘图的方向。
如从右到左的布局使用在诸如阿拉伯语、希伯来语等环境中。 此属性的默认值为inherit。
View.LAYOUT_DIRECTION_LTR(xml:ltr)从左到右,“en-US”中使用的方向;
View.LAYOUT_DIRECTION_RTL(xml:rtl)从右到左;
View.LAYOUT_DIRECTION_INHERIT(xml:inherit)从父控件继承;
View.LAYOUT_DIRECTION_LOCALE(xml:locale)使用“en-US”,即从左到右;


  • android:longClickable
void setLongClickable(boolean);

是否响应长按事件。


  • android:minHeight
void setMinimumHeight(int);

定义视图的最小高度。
不保证将能够达到此最小高度(例如,如果其父布局的高度更小)。


  • android:minWidth
void setMinimumWidth(int);

定义视图的最小宽度。
不保证将能够实现此最小宽度(例如,如果其父布局的宽度更小)。


  • android:nestedScrollingEnabled
void setNestedScrollingEnabled(boolean);

是否允许嵌套滑动。


  • android:nextClusterForward
void setNextClusterForwardId(int);

定义下一个键盘导航集群。
如果该引用引用的视图不存在或者是不可见的层次结构的一部分,则在访问引用时将产生RuntimeException。(这个也不太明白)


  • android:nextFocusDown
void setNextFocusDownId(int);

当点down键时,哪个控件将获得焦点。


  • android:nextFocusForward
void setNextFocusForwardId(int);

设置指定视图获得下一个焦点。


  • android:nextFocusLeft
void setNextFocusLeftId(int);

当点left键时,哪个控件将获得焦点。


  • android:nextFocusRight
void setNextFocusRightId(int);

当点right键时,哪个控件将获得焦点。


  • android:nextFocusUp
void setNextFocusUpId(int);

当点up键时,哪个控件将获得焦点。


  • android:onClick
void setOnClickListener(OnClickListener);

单击视图时要调用的此View上下文中方法的名称。
此名称必须对应于一个public方法,该方法只接受一个View类型的参数。
例如,如果指定android:onClick ="sayHello",则必须声明上下文(通常是Activity)的public void sayHello(View v)方法。


  • android:outlineProvider
void setOutlineProvider(ViewOutlineProvider);

设置轮廓。
null(xml:none)不设置;
ViewOutlineProvider.BACKGROUND(xml:background)根据背景设置;
ViewOutlineProvider.BOUNDS(xml:bounds)根据View设置;
ViewOutlineProvider.PADDED_BOUNDS(xml:paddedBounds)根据View设置,除去padding部分;


  • android:overScrollMode
void setOverScrollMode(int);

一般支持可滚动的布局或控件,如SrollView、ListView、RecycleView、ViewPager等,设置当滚动到边界时的效果。
View.OVER_SCROLL_NEVER(xml:never)不触发;
View.OVER_SCROLL_IF_CONTENT_SCROLLS(xml:ifContentScrolls)当内容可滚动时触发;
View.OVER_SCROLL_ALWAYS(xml:always)都触发;


  • android:padding
void setPadding(int, int, int, int);
void setPaddingRelative(int, int, int, int);

上下左右内边距。


  • android:paddingBottom
void setPadding(int, int, int, int);
void setPaddingRelative(int, int, int, int);

底部内边距。


  • android:paddingEnd
void setPaddingRelative(int, int, int, int);

末尾部分内边距。


  • android:paddingHorizontal
void setPadding(int, int, int, int);
void setPaddingRelative(int, int, int, int);

左右内边距。


  • android:paddingLeft
void setPadding(int, int, int, int);

左边内边距。


  • android:paddingRight
void setPadding(int, int, int, int);

右边内边距。


  • android:paddingStart
void setPaddingRelative(int, int, int, int);

开头部分内边距。


  • android:paddingTop
void setPadding(int, int, int, int);
void setPaddingRelative(int, int, int, int);

顶部内边距。


  • android:paddingVertical
void setPadding(int, int, int, int);
void setPaddingRelative(int, int, int, int);

上下内边距。


  • android:pointerIcon
void setPointerIcon(PointerIcon);

鼠标图标。
PointerIcon.TYPE_NULL(xml:none)不可见;
PointerIcon.TYPE_ARROW(xml:arrow)默认箭头;
PointerIcon.TYPE_CONTEXT_MENU(xml:context_menu)指示上下文菜单;
PointerIcon.TYPE_HAND(xml:hand)伸出食指的手;
PointerIcon.TYPE_HELP(xml:help)帮助;
PointerIcon.TYPE_WAIT(xml:wait)等待;
PointerIcon.TYPE_CELL(xml:cell)细胞和网格;
PointerIcon.TYPE_CROSSHAIR(xml:crosshair)十字准线,表明发现一个位置;
PointerIcon.TYPE_TEXT(xml:text)工字型,表示文本输入;
PointerIcon.TYPE_VERTICAL_TEXT(xml:vertical_text)用于垂直文本的90度旋转工字型的指针图标;
PointerIcon.TYPE_ALIAS(xml:alias)创建快捷方式;
PointerIcon.TYPE_COPY(xml:copy)拖放;
PointerIcon.TYPE_NO_DROP(xml:no_drop)不可以拖拽到当前位置;
PointerIcon.TYPE_ALL_SCROLL(xml:all_scroll)四向箭头,表示滚动所有方向;
PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW(xml:horizontal_double_arrow)水平双箭头,表明水平调整大小;
PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW(xml:vertical_double_arrow)垂直双箭头,表明垂直调整大小;
PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW(xml:top_right_diagonal_double_arrow)对角双箭头,从右上角到左下角。 指示自由形式调整大小;
PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW(xml:top_left_diagonal_double_arrow)对角双箭头,从左上角到右下角。 指示自由形式调整大小;
PointerIcon.TYPE_ZOOM_IN(xml:zoom_in)放大;
PointerIcon.TYPE_ZOOM_OUT(xml:zoom_out)缩小;
PointerIcon.TYPE_GRAB(xml:grab)抓取;
PointerIcon.TYPE_GRABBING(xml:grabbing)正在抓取


  • android:requiresFadingEdge
void setHorizontalFadingEdgeEnabled(boolean);
void setVerticalFadingEdgeEnabled(boolean);

定义滚动时哪些边应该褪色。


  • android:rotation
void setRotation(float);

旋转视图,以度为单位。


  • android:rotationX
void setRotationX(float);

围绕x轴旋转视图,以度为单位。


  • android:rotationY
void setRotationY(float);

绕y轴旋转视图,以度为单位。


  • android:saveEnabled
void setSaveEnabled(boolean);

如果为false,则在冻结该视图时不会保存任何状态。
默认值为true,允许保存视图,但是也必须为其分配ID以保存其状态。
将此设置为false仅禁用此视图的状态,不会禁用子控件。


  • android:scaleX
void setScaleX(float);

x方向视图的缩放。


  • android:scaleY
void setScaleY(float);

y方向视图的缩放。


  • android:scrollIndicators
void setScrollIndicators(int);
void setScrollIndicators(int, int);

定义可以滚动视图时应显示的滚动指示符。


  • android:scrollX
void setScrollX(int);

初始水平滚动偏移,以像素为单位。


  • android:scrollY
void setScrollY(int);

初始垂直滚动偏移,以像素为单位。


  • android:scrollbarAlwaysDrawHorizontalTrack
//没有相应的代码接口

是否应始终绘制水平滚动条轨道。


  • android:scrollbarAlwaysDrawVerticalTrack
//没有相应的代码接口

是否应始终绘制垂直滚动条轨道。


  • android:scrollbarDefaultDelayBeforeFade
void setScrollBarDefaultDelayBeforeFade(int);

定义滚动条在淡出之前等待的延迟(以毫秒为单位)。


  • android:scrollbarFadeDuration
void setScrollBarFadeDuration(int);

定义滚动条淡出所用的时间(以毫秒为单位)。


  • android:scrollbarSize
void setScrollBarSize(int);

设置垂直滚动条的宽度和水平滚动条的高度。


  • android:scrollbarStyle
void setScrollBarStyle(int);

控制滚动条样式和位置
View.SCROLLBARS_INSIDE_OVERLAY(xml:insideOverlay)在padding区域内并且覆盖在view上;
View.SCROLLBARS_INSIDE_INSET(xml:insideInset)在padding区域内并且插入在view后面;
View.SCROLLBARS_OUTSIDE_OVERLAY(xml:outsideOverlay)在padding区域外并且覆盖在view上;
View.SCROLLBARS_OUTSIDE_INSET(xml:outsideInset)在padding区域外并且插入在view后面;


  • android:scrollbarThumbHorizontal
//没有相应的代码接口

水平滚动条thumb图片。


  • android:scrollbarThumbVertical
//没有相应的代码接口

垂直滚动条thumb图片。


  • android:scrollbarTrackHorizontal
//没有相应的代码接口

水平滚动条轨道图片。


  • android:scrollbarTrackVertical
//没有相应的代码接口

垂直滚动条轨道图片。


  • android:scrollbars
void setVerticalScrollBarEnabled(boolean);
void setHorizontalScrollBarEnabled(boolean);

定义滚动时应显示哪些滚动条。


  • android:soundEffectsEnabled
void setSoundEffectsEnabled(boolean);

按键提示音。


  • android:stateListAnimator
void setStateListAnimator(StateListAnimator);

状态(焦点,按下等)改变时的动画效果。


  • android:tag
void setTag(Object);

为此视图提供包含String的标记,可以使用View.getTag()获得tag或使用View.findViewWithTag()搜索。


  • android:textAlignment
void setTextAlignment(int);

文本的对齐方式。
View.TEXT_ALIGNMENT_INHERIT(xml:inherit)默认;
View.TEXT_ALIGNMENT_GRAVITY(xml:gravity)相对于每个段落的文本方向;
View.TEXT_ALIGNMENT_TEXT_START(xml:textStart)对其段落开头;
View.TEXT_ALIGNMENT_TEXT_END(xml:textEnd)对其段落末尾;
View.TEXT_ALIGNMENT_CENTER(xml:center)段落居中;
View.TEXT_ALIGNMENT_VIEW_START(xml:viewStart)对其视图开头,相对于layoutDirection;
View.TEXT_ALIGNMENT_VIEW_END(xml:viewEnd)对其视图末尾,相对于layoutDirection;


  • android:textDirection
void setTextDirection(int);

定义文本的方向。
View.TEXT_DIRECTION_INHERIT(xml:inherit)默认;
View.TEXT_DIRECTION_FIRST_STRONG(xml:firstStrong)第一个强制方向字符决定段落方向。 如果没有强制方向字符,则段落方向是视图的已解析布局方向;
View.TEXT_DIRECTION_ANY_RTL(xml:anyRtl)如果它包含任何强制为RTL字符则段落方向是RTL,如果它包含任何强制为LTR字符则段落方向是LTR。 如果两者都没有,则段落方向是视图已解析布局方向;
View.TEXT_DIRECTION_LTR(xml:ltr)段落方向从左到右;
View.TEXT_DIRECTION_RTL(xml:rtl)段落方向从右到左;
View.TEXT_DIRECTION_LOCALE(xml:locale)系统判断;
View.TEXT_DIRECTION_FIRST_STRONG_LTR(xml:firstStrongLtr)第一个强制方向字符决定段落方向。 如果没有强制方向性,则段落方向为LTR;
View.TEXT_DIRECTION_FIRST_STRONG_RTL(xml:firstStrongRtl)第一个强制方向字符决定段落方向。 如果没有强制方向性,则段落方向为LTR;


  • android:theme
//没有相应的代码接口
//在View实例化时可传入

指定主题。
设置主题时,将使用以指定资源为主题的上下文对视图进行填充。


  • android:tooltipText
void setTooltipText(CharSequence);

定义在悬停或长按时在小弹出窗口中显示的文本。


  • android:transformPivotX
void setPivotX(float);

x轴上的位置,视图将围绕该位置旋转和缩放。


  • android:transformPivotY
void setPivotY(float);

y轴上的位置,视图将围绕该位置旋转和缩放。


  • android:transitionName
void setTransitionName(String);

activity切换时设置标识


  • android:translationX
void setTranslationX(float);

x轴偏移量。


  • android:translationY
void setTranslationY(float);

y轴偏移量。


  • android:translationZ
void setTranslationZ(float);

z轴偏移量。


  • android:verticalScrollbarPosition
view.setVerticalScrollbarPosition(int);

确定垂直滚动条应放在哪一侧。
View.SCROLLBAR_POSITION_DEFAULT(xml:defaultPosition)系统默认;
View.SCROLLBAR_POSITION_LEFT(xml:left)左边;
`View.SCROLLBAR_POSITION_RIGHT(xml:right)右边;


  • android:visibility
void setVisibility(int visibility);

view可见状态。
View.VISIBLE(xml:visible)可见;
View.INVISIBLE(xml:invisible)不可见但占用空间;
View.GONE(xml:gone)不可见也不占用空间;


然后更新了一下插件,支持了View类中的属性

<View
        android:id="@+id/v1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:accessibilityLiveRegion="polite"
        android:accessibilityTraversalAfter="@id/v1"
        android:accessibilityTraversalBefore="@id/v1"
        android:alpha="0.5"
        android:autofillHints="password"
        android:background="@color/colorAccent"
        android:backgroundTint="@color/colorPrimary"
        android:backgroundTintMode="src_in"
        android:clickable="true"
        android:contentDescription="@string/app_name"
        android:contextClickable="true"
        android:defaultFocusHighlightEnabled="true"
        android:drawingCacheQuality="high"
        android:duplicateParentState="true"
        android:elevation="2dp"
        android:fadeScrollbars="true"
        android:fadingEdge="vertical|horizontal"
        android:fadingEdgeLength="3dp"
        android:filterTouchesWhenObscured="true"
        android:fitsSystemWindows="true"
        android:focusable="auto"
        android:focusableInTouchMode="true"
        android:focusedByDefault="true"
        android:forceHasOverlappingRendering="true"
        android:foreground="@mipmap/ic_launcher"
        android:foregroundGravity="clip_horizontal"
        android:foregroundTint="@color/colorPrimaryDark"
        android:foregroundTintMode="src_in" />

    <View
        android:id="@+id/v2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hapticFeedbackEnabled="true"
        android:importantForAccessibility="noHideDescendants"
        android:importantForAutofill="yesExcludeDescendants"
        android:isScrollContainer="true"
        android:keepScreenOn="true"
        android:keyboardNavigationCluster="true"
        android:labelFor="@id/v1"
        android:layerType="hardware"
        android:layoutDirection="rtl"
        android:longClickable="true"
        android:minHeight="12dp"
        android:minWidth="11dp"
        android:nestedScrollingEnabled="true"
        android:nextClusterForward="@id/v2"
        android:nextFocusDown="@id/v2"
        android:nextFocusForward="@id/v2"
        android:nextFocusLeft="@id/v2"
        android:nextFocusRight="@id/v2"
        android:nextFocusUp="@id/v2"
        android:onClick="as"
        android:outlineProvider="none"
        android:overScrollMode="ifContentScrolls"
        android:padding="12dp"
        android:paddingBottom="23dp"
        android:paddingEnd="22dp"
        android:paddingHorizontal="11dp"
        android:paddingLeft="22dp"
        android:paddingRight="11dp"
        android:paddingStart="33dp"
        android:paddingTop="44dp"
        android:paddingVertical="55dp"
        android:pointerIcon="zoom_in" />

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:requiresFadingEdge="horizontal"
        android:rotation="90"
        android:rotationX="20"
        android:rotationY="45"
        android:saveEnabled="true"
        android:scaleX="0.6"
        android:scaleY="0.5"
        android:scrollIndicators="right"
        android:scrollX="12dp"
        android:scrollY="22dp"
        android:scrollbarAlwaysDrawHorizontalTrack="true"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:scrollbarDefaultDelayBeforeFade="12"
        android:scrollbarFadeDuration="70"
        android:scrollbarSize="12dp"
        android:scrollbarStyle="outsideOverlay"
        android:scrollbarThumbHorizontal="@drawable/ic_launcher_background"
        android:scrollbarThumbVertical="@drawable/ic_launcher_background"
        android:scrollbarTrackHorizontal="@drawable/ic_launcher_background"
        android:scrollbarTrackVertical="@color/colorPrimary"
        android:scrollbars="none"
        android:soundEffectsEnabled="true"
        android:stateListAnimator="@drawable/ic_launcher_background"
        android:tag="tag"
        android:textAlignment="viewStart"
        android:textDirection="locale"
        android:theme="@style/AlertDialog.AppCompat"
        android:tooltipText="@string/app_name"
        android:transformPivotX="1dp"
        android:transformPivotY="12dp"
        android:transitionName="@string/appbar_scrolling_view_behavior"
        android:translationX="12dp"
        android:translationY="5dp"
        android:translationZ="22dp"
        android:verticalScrollbarPosition="left"
        android:visibility="visible" />

转换之后

            view {
                id = R.id.v1
                accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_POLITE
                accessibilityTraversalAfter = R.id.v1
                accessibilityTraversalBefore = R.id.v1
                alpha = 0.5f
                setAutofillHints(View.AUTOFILL_HINT_PASSWORD)
                backgroundColor = resources.getColor(R.color.colorAccent)
                backgroundTintList = resources.getColorStateList(R.color.colorPrimary)
                backgroundTintMode = PorterDuff.Mode.SRC_IN
                isClickable = true
                contentDescription = resources.getString(R.string.app_name)
                isContextClickable = true
                defaultFocusHighlightEnabled = true
                drawingCacheQuality = View.DRAWING_CACHE_QUALITY_HIGH
                isDuplicateParentStateEnabled = true
                elevation = dip(2).toFloat()
                isScrollbarFadingEnabled = true
                isVerticalFadingEdgeEnabled = true
                isHorizontalFadingEdgeEnabled = true
                setFadingEdgeLength(dip(3))
                filterTouchesWhenObscured = true
                fitsSystemWindows = true
                //android:focusable = auto //Auto is default
                isFocusableInTouchMode = true
                isFocusedByDefault = true
                forceHasOverlappingRendering(true)
                foreground = resources.getDrawable(R.mipmap.ic_launcher)
                foregroundGravity = Gravity.CLIP_HORIZONTAL
                foregroundTintList = resources.getColorStateList(R.color.colorPrimaryDark)
                foregroundTintMode = PorterDuff.Mode.SRC_IN
            }
            view {
                id = R.id.v2
                isHapticFeedbackEnabled = true
                importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
                importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS
                isScrollContainer = true
                keepScreenOn = true
                isKeyboardNavigationCluster = true
                labelFor = R.id.v2
                setLayerType(View.LAYER_TYPE_HARDWARE, null)
                layoutDirection = View.LAYOUT_DIRECTION_RTL
                isLongClickable = true
                minimumHeight = dip(12)
                minimumWidth = dip(11)
                isNestedScrollingEnabled = true
                nextClusterForwardId = R.id.v2
                nextFocusDownId = R.id.v2
                nextFocusForwardId = R.id.v2
                nextFocusLeftId = R.id.v2
                nextFocusRightId = R.id.v2
                nextFocusUpId = R.id.v2
                setOnClickListener {
                    //as()
                }
                outlineProvider = ViewOutlineProvider.BACKGROUND
                overScrollMode = View.OVER_SCROLL_IF_CONTENT_SCROLLS
                padding = dip(12)
                bottomPadding = dip(23)
                setPaddingRelative(paddingStart, paddingTop, dip(22), paddingBottom)
                horizontalPadding = dip(11)
                leftPadding = dip(22)
                rightPadding = dip(11)
                setPaddingRelative(dip(33), paddingTop, paddingEnd, paddingBottom)
                topPadding = dip(44)
                verticalPadding = dip(55)
                pointerIcon = PointerIcon.getSystemIcon(context, PointerIcon.TYPE_ZOOM_IN)
            }
            themedView(R.style.AlertDialog_AppCompat) {
                isVerticalFadingEdgeEnabled = false
                isHorizontalFadingEdgeEnabled = true
                rotation = 90.0f
                rotationX = 20.0f
                rotationY = 45.0f
                isSaveEnabled = true
                scaleX = 0.6f
                scaleY = 0.5f
                scrollIndicators = View.SCROLL_INDICATOR_RIGHT
                scrollX = dip(12)
                scrollY = dip(22)
                //android:scrollbarAlwaysDrawHorizontalTrack = true //Can not be set by code
                //android:scrollbarAlwaysDrawVerticalTrack = true //Can not be set by code
                scrollBarDefaultDelayBeforeFade = 12
                scrollBarFadeDuration = 70
                scrollBarSize = dip(12)
                scrollBarStyle = View.SCROLLBARS_OUTSIDE_OVERLAY
                //android:scrollbarThumbHorizontal = @drawable/ic_launcher_background //Can not be set by code
                //android:scrollbarThumbVertical = @drawable/ic_launcher_background //Can not be set by code
                //android:scrollbarTrackHorizontal = @drawable/ic_launcher_background //Can not be set by code
                //android:scrollbarTrackVertical = @color/colorPrimary //Can not be set by code
                isVerticalScrollBarEnabled = false
                isHorizontalScrollBarEnabled = false
                isSoundEffectsEnabled = true
                stateListAnimator = AnimatorInflater.loadStateListAnimator(context, R.drawable.ic_launcher_background)
                tag = "tag"
                textAlignment = View.TEXT_ALIGNMENT_VIEW_START
                textDirection = View.TEXT_DIRECTION_LOCALE
                tooltipText = resources.getString(R.string.app_name)
                pivotX = dip(1).toFloat()
                pivotY = dip(12).toFloat()
                transitionName = resources.getString(R.string.appbar_scrolling_view_behavior)
                translationX = dip(12).toFloat()
                translationY = dip(5).toFloat()
                translationZ = dip(22).toFloat()
                verticalScrollbarPosition = View.SCROLLBAR_POSITION_LEFT
                visibility = View.VISIBLE
            }.lparams(width = matchParent, height = matchParent)
xml1.png

anko1.png

xml2.png

anko2.png

xml3.png

anko3.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,636评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,890评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,680评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,766评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,665评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,045评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,515评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,182评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,334评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,274评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,319评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,002评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,599评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,675评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,917评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,309评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,885评论 2 341

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 171,263评论 25 707
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,375评论 1 45
  • 还是那个万年不变的问题,运营到底是做啥的?在不清楚这个问题的情况下,很多做运营的同学,都感觉自己无所事事,一方面的...
    老虎讲运营阅读 301评论 0 0
  • 坚持分享第475天 2018.06.25 焦点解决短期心理治疗中眼光特别的重要,作为老师要刻意的训练关注孩...
    双月芽儿阅读 481评论 0 0
  • 一场微风 我仰起脸 感受 流星划过夜空 平躺睡椅 数落星落的空 吹到我的心中 甜谧 温暖的感动 球场的路灯 展耀着...
    人生请多逗留阅读 113评论 0 0