【发布时间】:2014-04-17 13:19:18
【问题描述】:
我有一个 Customer Spinner,里面有图片。现在,除了两件小事之外,一切都按预期进行:
- 微调器没有显示,只有一条细细的线。
- 微调器项目的灰色边框有点延伸。
我在下面添加了这些问题的截图:
我想要的是:
- 我想要一个空的 CheckBox 图像,而不是上面的细线。
- 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