文本被推向左侧的喷丝 - 机器人 [英] Text is pushed to the left in a spinner - Android

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

问题描述

我要建一个Android应用程序,和我有一个愚蠢的问题 -

I'm building an android app, and I have a stupid question -

我有一个风格微调。风格只包含一个背景的微调。的问题是,无论哪个图像I使用的背景下,纺丝器的文本总是被压向左边。

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声明 -

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>

这是结果 -

And this is the result -

<一个href="http://img199.imageshack.us/i/spinners.png/">http://img199.imageshack.us/i/spinners.png/

另外,我得到了Android下一个警告:重力属性,它说,这是一个未知的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. Any help will do.

感谢

推荐答案

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

Continuing from my last comment above...

下面code修改的Hello微调教程应用程序显示喷丝文本内容水平居中,如以下两个截图所示。

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 /布局/ 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.

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

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