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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:24:58  来源:igfitidea点击:

Align spinner values to right instead of left

androidxmlandroid-layoutalignmentspinner

提问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:gravityto 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 TextAlignmenton properties and select TextEnd, or android:textAlignment="textEnd"on XML simple

您可以使用TextAlignmenton properties 和 select TextEnd,或者android:textAlignment="textEnd"使用简单的 XML