【问题标题】:android spinner not sizing properlyandroid微调器大小不正确
【发布时间】:2015-05-31 04:30:29
【问题描述】:

上面是我的应用程序中的“详细信息”线性布局。正如您所看到的,微调器似乎比“Level 1”和“Per Level”下降得更多。我已经弄乱了 xml 以尝试将所有内容都放在一个共同的基础上,而不会使微调器掉下来,但我就是想不通。我尝试将微调器高度设置为“fill_parent”,它确实在同一基线上,但微调器内没有显示任何文本。有没有人知道该怎么做?

它们所在布局的 XML:

<LinearLayout
        android:id="@+id/details"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:baselineAligned="false"
        android:orientation="horizontal" >



        <TextView
            android:id="@+id/blank"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="2" />

        <TextView
            android:id="@+id/levelOne"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/level_1" />

        <TextView
            android:id="@+id/perLevel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/per_level" />


        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

    </LinearLayout>

这是我在微调器内的文本的 XML:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/spinnerDisplay"
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:textSize="12sp">

</TextView>

我在我的班级中使用它来填充我想要的文本大小:

spinLevels = (Spinner) view.findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.LevelChosen, R.layout.spinner_item);      
spinLevels.setAdapter(adapter);

【问题讨论】:

    标签: android xml layout spinner


    【解决方案1】:

    在 XML 中的 Spinner 上,添加以下行:

    android:layout_gravity="center_vertical"
    

    这应该在布局中垂直居中。

    【讨论】:

      【解决方案2】:

      我想通了,我只需要从细节布局中删除“android:baselineAligned="false"。

      【讨论】:

        【解决方案3】:

        以上都不起作用。对我有用的是“权重”

        android:layout_width="fill_parent"
        android:layout_weight="1"
        

        【讨论】:

          猜你喜欢
          • 2011-10-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-10-24
          • 2016-08-07
          相关资源
          最近更新 更多