【问题标题】:Android Spinner with images finishing带有图像整理功能的 Android Spinner
【发布时间】:2014-04-17 13:19:18
【问题描述】:

我有一个 Customer Spinner,里面有图片。现在,除了两件小事之外,一切都按预期进行:

  1. 微调器没有显示,只有一条细细的线。
  2. 微调器项目的灰色边框有点延伸。

我在下面添加了这些问题的截图:

我想要的是:

  1. 我想要一个空的 CheckBox 图像,而不是上面的细线。
  2. Spinner 项目的图片右侧是灰色部分,应将其移除。

我知道这两个问题都存在于 xml 文件中,但我对 Android 有点陌生,而且我总是对何时使用哪个 layout_widht/height 感到有些困惑。

这里是 xml 文件:

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context="com.example.testproject.MainActivity$PlaceholderFragment" >

    <Spinner 
        android:id="@+id/spCheckbox"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:drawSelectorOnTop="true" />

    <ImageButton
            android:id="@+id/ibtnCheckbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:contentDescription="@string/checkbox_content_description"
            android:src="@drawable/checkbox_unchecked"
            android:background="@drawable/transparent_background" />

</LinearLayout>

spinner_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/cbImage"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/transparent_button_background" />

</RelativeLayout>

(transparent_background.xml:)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@android:color/transparent" />
    <item android:state_pressed="true" android:drawable="@android:color/transparent" />
    <item android:drawable="@android:color/transparent" />
</selector>

那么.. 我需要更改哪个 layout_width / layout_height 才能获得正确的结果?

提前感谢您的回复。

编辑:我做了一些研究,并开始用 match_parent 替换所有 fill_parent(因为它是相同的,并且在 API lvl. 8 之后不推荐使用 fill_parent)。对于我的问题,似乎我的 activity_main 布局应该是 match_parent 才能全屏,而 Spinner、Spinner Item 的 Layout 和 Spinner Item 的 ImageView 都应该是 wrap_content。

不过,如果我把它改成那样,这两个问题仍然是一样的。如果有人知道如何显示 Spinner 的选定图像以及如何删除 Spinner 项的灰色间距,请告诉我。

【问题讨论】:

    标签: android xml android-layout android-relativelayout android-xml


    【解决方案1】:

    解决了细线而不是 Spinner 的问题。事实证明,当我在互联网上某处关注教程时,他们添加了这条线:

    spinner.getLayoutParams().width = 3;
    

    显然,删除这条线解决了第一个问题.. >.>(不知道为什么他们首先添加了这个,但现在它已经消失了,我看到我的微调器正常)

    现在我只需要解决灰色边框的第二个问题,但我相信我最终会找到解决方案..

    编辑:由于除了灰色填充之外,我还想删除微调器右下箭头,因此我决定完全删除微调器并创建一个具有垂直方向的 LineairLayout 的弹出窗口。强>

    有关代码的参考,我将其发布在another question of mine

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 2013-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多