安卓系统中的旋转器控件的图形问题[英] Graphical issue with spinner control in Android

本文是小编为大家收集整理的关于安卓系统中的旋转器控件的图形问题的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我的第一个(旧)Android应用程序(暂停计算器 )显示一个问题我找不到解决方案:的旋转控制器,一些旋转器在不需要的地方显示透明线.模式是:每隔一个旋转器都是在第一个旋转器控制开始的问题.因此,虽然旋转器2,4,6,......没有不需要的线,旋转器1,3,5,......含它们.

下面的图像(下面的链接)在红色分隔符之后首先显示所选状态的旋转器,并在未选择状态下.在所选状态下,透明线是整个控制的基线高度除可以是按钮文本的一些位置.在未选择的状态下它有点不同.

我不能直接提供图像:

[...]作为垃圾邮件预防机制,新的 用户不允许发布图像.

但我可以给你一个链接:

屏幕截图,说明了图形旋转器问题

res/layout下的XML文件如下所示:

<ScrollView ...>
    <TableLayout ...>
        <TableRow>
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/units"
                android:gravity="center_vertical"
                android:paddingRight="5dp"
            />
            <Spinner
                android:id="@+id/unit_spinner"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:drawSelectorOnTop="true"
            />
        </TableRow>
        ...
    </TableLayout>
</ScrollView>

自弗洛科(Android 2.2)以来,我至少看到这个问题.在早期版本中(至少是Android 1.6),它不存在.它不是在Eclipse的图形布局编辑器中,但我看到它在手机和仿真器上运行了应用程序 - 这至少是一个不一致的,并且暗示了我造成的问题,而不是做正确的事情; - ).

推荐答案

实际上我可以在android 2.3上重现此行为.在Android 2.2和更低的情况下不可能.

如果您将旋转器放在表单中或相对的内容中,它无关紧要.那里的问题相同..

只能获得线路的解决方案是在旋转器之间放置1px视图:

<Spinner android:layout_height="wrap_content" android:id="@+id/spinnerDriver"
    android:layout_width="match_parent" android:layout_below="@id/driverDesc" />

<View android:id="@+id/helper" android:layout_height="1px"
    android:layout_width="match_parent" android:layout_below="@id/spinnerDriver" />

<Spinner android:layout_height="wrap_content" android:id="@+id/spinnerDriver1"
    android:layout_width="match_parent" android:layout_below="@id/helper" />

这实际上是一个非常非常非常的解决方案,但它适用于我...

本文地址:https://www.itbaoku.cn/post/102413.html

问题描述

My first (old) Android app (Suspension Calculator) is showing a problem I cannot find a solution for: the spinner control on some spinners is showing transparent lines in unwanted places. The pattern is this: every other spinner is having this problem, starting with the first spinner control. So while spinners 2, 4, 6, ... have no unwanted lines, spinners 1, 3, 5, ... have them.

The following image (link below) shows the spinner in selected state first, and in unselected state after the red separator. In selected state, the transparent line is at baseline height for the entire control except some places where the button text can be. It's a little different in unselected state.

I cannot provide an image directly:

[...] as a spam prevention mechanism, new users aren't allowed to post images.

But I can give you a link:

Screenshot that illustrated the graphical spinner problem

The XML file under res/layout looks like this:

<ScrollView ...>
    <TableLayout ...>
        <TableRow>
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/units"
                android:gravity="center_vertical"
                android:paddingRight="5dp"
            />
            <Spinner
                android:id="@+id/unit_spinner"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:drawSelectorOnTop="true"
            />
        </TableRow>
        ...
    </TableLayout>
</ScrollView>

I see this problem at least since Froyo (Android 2.2). In earlier versions (at least Android 1.6), it wasn't there. It's not there in the Graphical Layout editor in Eclipse, but I see it running the application on the phone and in the emulator - that's at least consistent and hints to a problem I'm causing by not doing things right ;-).

推荐答案

Actually I can reproduce this behavior on Android 2.3. Not possible on Android 2.2 and lower.

It' doesn't matter if you place the Spinner in a TableLayout or RelativeLayout. Same problem there..

Only solution to get ride of the lines was to put a 1px-View between the spinner:

<Spinner android:layout_height="wrap_content" android:id="@+id/spinnerDriver"
    android:layout_width="match_parent" android:layout_below="@id/driverDesc" />

<View android:id="@+id/helper" android:layout_height="1px"
    android:layout_width="match_parent" android:layout_below="@id/spinnerDriver" />

<Spinner android:layout_height="wrap_content" android:id="@+id/spinnerDriver1"
    android:layout_width="match_parent" android:layout_below="@id/helper" />

This is actually a very, very, very... ugly solution but it works for me...