
是否可以移动下拉箭头,以便根据当前选择的选项动态定位?
特别是当第一个选项只是“全部”时,当下拉箭头离右边很远时,看起来很奇怪.
请参阅Google翻译应用,其中下拉箭头始终位于其文字旁边:
<Spinner androID:ID="@+ID/spinner_main" androID:spinnerMode="dropdown" androID:background="@null" androID:layout_wIDth="wrap_content" androID:layout_height="match_parent"/>
然后创建一个只有TextVIEw的布局资源spinner_item_main.xml,我们可以通过它的右侧设置一个drawable(你可以从here下载箭头图片):
<TextVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:textSize="20sp" androID:textStyle="bold" androID:gravity="left" androID:textcolor="@color/colorWhite" androID:drawableRight="@drawable/ic_arrow_drop_down_white_24dp" />
最后在初始化Spinner时设置此布局资源,您还可以提供资源作为下拉视图(就像我所做的那样):
(我用kotlin)
spinner_main.adapter = ArrayAdapter<String>(this,R.layout.spinner_item_main,objects).apply { setDropDownVIEwResource(R.layout.spinner_dropdown_vIEw_main) } 做了!
View this in My APP
以上是内存溢出为你收集整理的Android Spinner – 如果选项长度不同,如何将下拉箭头定位为尽可能接近文本?全部内容,希望文章能够帮你解决Android Spinner – 如果选项长度不同,如何将下拉箭头定位为尽可能接近文本?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)