Android 将微调器值向右而不是向左对齐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10629768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Align spinner values to right instead of left
提问by David
In spinner xml, I'm using:
在微调器 xml 中,我使用:
android:entries="@array/cars"
where cars is list of numeric items.
其中汽车是数字项目的列表。
The spinner automatically align values to left, and I can't find in xml/code how to change it.
微调器自动将值左对齐,我在 xml/code 中找不到如何更改它。
回答by Lalit Poptani
You have to use a custom view here to give alignment to the Spinner values. Create a CustomView like thisanswer has created and add android:gravity
to the TextView as right
.
您必须在此处使用自定义视图来对齐 Spinner 值。创建一个像这个答案已经创建的 CustomView并添加android:gravity
到 TextView as right
。
UPDATE:
更新:
Set the CustomView to your adapter using
使用将 CustomView 设置为您的适配器
adapter.setDropDownViewResource(android.R.layout.your_custom_created_view);
回答by Eddy Charry
You can use TextAlignment
on properties and select TextEnd
,
or android:textAlignment="textEnd"
on XML simple
您可以使用TextAlignment
on properties 和 select TextEnd
,或者android:textAlignment="textEnd"
使用简单的 XML