【问题标题】:How can I align text of the spinner to the centre?如何将微调器的文本对齐到中心?
【发布时间】:2013-05-19 16:43:59
【问题描述】:

这是我的微调器 XML,但它不起作用。

  <Spinner
        android:id="@+id/frequency"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/spinner_voices"
        android:gravity="center|center_horizontal"
         />

【问题讨论】:

标签: java android xml


【解决方案1】:

您需要为微调器项目设置自己的布局。

ArrayAdapter adap = new ArrayAdapter<String>(this, R.layout.spinner_item, new String[]{"ABC", "DEF", "GHI"});
spriner.setAdapter(adap);

其中 R.layout.spinner_item 是带有内容的布局:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent"
    android:layout_width="fill_parent" 
    android:gravity="center"/>

【讨论】:

  • Thnx,但这是文本视图,我正在使用我认为的微调器,我是 android 新手请帮助
  • 首先为 textview 创建一个布局并设置到 arrayAdapter 中,然后在 spinner 中设置该适配器。
猜你喜欢
  • 2021-03-21
  • 2012-11-11
  • 2015-08-05
  • 2016-03-13
  • 2011-11-22
  • 2014-06-03
  • 1970-01-01
  • 1970-01-01
  • 2014-09-15
相关资源
最近更新 更多