【问题标题】:Custom Spinner too thin自定义微调器太薄
【发布时间】:2021-01-29 22:55:38
【问题描述】:

我正在为我的 Spinner 创建一个自定义布局,其代码如下:

 <!-- spinner_item.xml -->
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:textSize="20sp"
        android:gravity="left"
        android:textColor="#FF0000"
        android:layout_marginTop="0dp"
        android:width="50dp"
        android:layout_marginBottom="40dp"/>

并使用如下:ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.spinner_item,list);

结果如下:

但是每个元素都太细了,所以我用了padding-top但是效果很差:

当我选择其中一个时,它不会出现在框中(我认为是因为它太宽了)。有没有办法做到这一点?谢谢。

【问题讨论】:

  • 您能否更详细地描述所需的结果?您希望微调器看起来像什么?您指的是哪个框?

标签: java android xml layout


【解决方案1】:

使用填充而不是边距

 <!-- spinner_item.xml -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:textSize="20sp"
    android:gravity="left"
    android:textColor="#FF0000"
     android:padding="10dp"/>

【讨论】:

  • 谢谢,我用了这个方法,就是我喜欢的样子,但是当我选择一个项目时,它并没有出现在 Spinner 的框中,你知道为什么吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-13
  • 2012-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多