Sil*_*ght 37 android android-support-library
当我开发时,我发现了一个android.support.v7.widget.ButtonBarLayout意外的新小部件.我试图在互联网上搜索它,但没有发现任何东西,即使在官方开发文档网站上也是如此.
与此同时,ButtonBarLayout当我ButtonBarLayout在Android Studio中搜索时,我发现了两个,一个是android.support.v7.widget.ButtonBarLayout,另一个是com.android.internal.widget.ButtonBarLayout.我试图读取两者的源代码,我发现除了包名称它们是相同的.所以我想也许android.support.v7.widget.ButtonBarLayout是com.android.internal.widget.ButtonBarLayout在内部ButtonBarLayout通过测试并发布之后.同时,ButtonBarLayout是继承自LinearLayout.
但是有一些问题:
ButtonBarLayout字面上得到什么,我们应该如何使用它?private boolean mAllowStacking.当它改变时,这种布局的方向将会改变.但我真的不明白它的用途.有人知道ButtonBarLayout吗?
PS:我使用过Android Studio的2.0.0预览版4和摇篮插件的2.0.0-素α3和Android的支持库的23.1.1和平台工具的23.1和构建工具的23.0.2.
nat*_*rio 38
正如其他人所指出的,类描述确切地说明了它是什么: an extension of LinearLayout that automatically switches to vertical orientation when it can't fit its child views horizontally.
我可以补充一点,这显然是为了符合关于对话框的材料设计规范.它们区分并排按钮和堆叠按钮.参见例如:
当每个标签的文本不超过最大按钮宽度时,建议使用并排按钮,例如常用的"确定/取消"按钮.
当单个按钮太大时,你应该选择堆叠按钮,或者两者都没有足够的空间:
当文本标签超出最大按钮宽度时,请使用堆叠按钮来容纳文本.肯定行动堆积在不屑一顾的行为之上.
因此,在设计自己的对话框时,可以使用此类.例如,AlertDialog并AlertDialog.Builder为带按钮的对话框提供内部支持,但有时您只想要子类DialogFragment或AppCompatDialogFragment更好地控制.
在那里,设置符合设计指南的底部按钮栏并完全控制按钮(如启用和禁用,AlertDialogAFAIK 无法做到的事情)可能很有用.
And*_*tel 14
的源代码描述ButtonBarLayout如下:
/**
* An extension of LinearLayout that automatically switches to vertical
* orientation when it can't fit its child views horizontally.
*/
Run Code Online (Sandbox Code Playgroud)
因此,从本质上讲,它只是一个LinearLayout基于屏幕上可用空间管理自动切换方向的智能.
同样的ButtonBarLayout.java文件mAllowStacking在评论中描述如下:
/** Whether the current configuration allows stacking. */
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11648 次 |
| 最近记录: |