Android-文本在微调器中被推到左侧 [英] Android - Text is Pushed to the Left in a Spinner

查看:52
本文介绍了Android-文本在微调器中被推到左侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有样式的微调框.样式仅包含微调框的背景.问题是,无论我使用哪个图像作为背景,微调框的文本始终被推到左侧.

I have a spinner with a style. The style only contains a background for the spinner. The problem is,that no matter which image I use for the background, the text of the spinner is always pushed to the left.

这是XML中Spinner的声明-

This is the declaration of the Spinner in the XML -

<Spinner
 android:layout_height="wrap_content"
 android:layout_toRightOf="@+id/minus"
 android:layout_width="wrap_content"
 android:layout_below="@+id/female"
 android:id="@+id/spin"
 android:gravity="center"
 android:background="@drawable/spin"
 android:layout_marginTop="10dip">
 </Spinner>

此外,我在android:gravity属性下收到一条警告,说它是未知的XML属性.

Also, I get a warning under the android:gravity attribute that says it's an unknown XML attribute.

我不知道为什么会这么做.

I can't figure why it does that.

谢谢

推荐答案

从上面我的最后一条评论继续...

Continuing from my last comment above...

以下代码将 Hello Spinner教程应用程序修改为如以下两个屏幕截图所示,显示微调器文本内容在水平居中位置.

The following code modifies the Hello Spinner tutorial application to display the spinner text contents centered horizontally, as seen in the following two screenshots.

res/layout/my_spinner_textview.xml

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

public class HelloSpinner extends Activity
{
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.planets_array,
//        android.R.layout.simple_spinner_item);
        R.layout.my_spinner_textview);
//    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    adapter.setDropDownViewResource(R.layout.my_spinner_textview);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
  }

  //No other modification needed.

这有望为解决该问题提供足够的指导.

This hopefully provides enough direction to fix the problem.

这篇关于Android-文本在微调器中被推到左侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆