文本被推向左侧的喷丝 - 机器人机器人、文本

2023-09-12 22:52:44 作者:℡倒不出的思念

我要建一个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 -

https://m.xsw88.com/allimgs/daicuo/20230912/291.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.