简体   繁体   English

Android 微调箭头始终高于其他视图

[英]Android spinner arrow always above other views

In my app, I have some spinners (each of which is part of a fragment) in a scrollView.在我的应用程序中,我在 scrollView 中有一些微调器(每个微调器都是片段的一部分)。 This scrollView is placed below a textView.此滚动视图位于 textView 下方。

The problem is that, when I'm running the app on my test device (Samsung Galaxy S6 Edge [G925F], API 23), the little arrow of the spinner stays visible above the textView, even though the rest of the spinner is already out of view.问题是,当我在我的测试设备(三星 Galaxy S6 Edge [G925F],API 23)上运行应用程序时,微调器的小箭头在 textView 上方保持可见,即使微调器的其余部分已经视而不见。

I did a lot of research but couldn't find any solutions, so I'm asking here: What do I need to do so that the arrows disappear like the rest of the spinner?我做了很多研究,但找不到任何解决方案,所以我在这里问:我需要做什么才能使箭头像微调器的其余部分一样消失?

Here some pictures:这里有一些图片:

In this picture, you can see the textView at the top of the activity and below the spinners, before I scrolled down在这张图片中,在我向下滚动之前,您可以在活动顶部和微调器下方看到 textView

In this screenshot, you can see the problem.在此屏幕截图中,您可以看到问题。 The little triangles of the spinner are still visible, but the spinner itself is already scrolled out of view.微调器的小三角形仍然可见,但微调器本身已经滚出视图。

Here is the XML code of the fragment containing the spinner:这是包含微调器的片段的 XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout
    android:id="@+id/fragLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/gradeDisplay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="15dp"
        android:layout_marginLeft="15dp"
        android:text="1"
        android:textSize="30dp"/>
    <Spinner
        android:id="@+id/spinner"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="30dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:entries="@array/grades"/>
    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:layout_marginEnd="15dp"
        android:layout_marginRight="15dp"
        android:src="@drawable/ic_remove_black_24dp"
        android:background="@null"/>
</LinearLayout>
<Space
    android:layout_width="0dp"
    android:layout_height="5dp"
    android:layout_below="@id/fragLayout"/>
</RelativeLayout>

And here is the code of the MainActivitys content:这是 MainActivitys 内容的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="de.jeanma.android.avo.MainActivity"
tools:showIn="@layout/activity_main">
    <Space
        android:id="@+id/mainContentSpace"
        android:layout_width="match_parent"
        android:layout_height="16dp" />
    <TextView
        android:id="@+id/textView"
        android:layout_below="@id/mainContentSpace"
        android:layout_width="match_parent"
        android:text="Standard text"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:gravity="end"/>
    <ScrollView
        android:id="@+id/scrollView"
        android:layout_below="@id/textView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:id="@+id/layout"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:divider="@drawable/divider"
            android:showDividers="middle">
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

The fragments are added to the LinearLayout (@id/layout) by a Java method.这些片段通过 Java 方法添加到 LinearLayout (@id/layout)。 If needed, I will post that here as well.如果需要,我也会在这里发布。

I'm using Java 1.8.05 and the target SDK is 23, the minimum is 14. The code is written in Android Studio我使用的是 Java 1.8.05,目标 SDK 是 23,最小是 14。代码是在 Android Studio 中编写的

The textView with the problems is the @id/textView , displaying the large number at the top.有问题的 textView 是@id/textView ,在顶部显示大数字。

@jeanma you can fix the issue with just setting @jeanma 您只需设置即可解决问题

android:background="#00FFFFFF"

for your ScrollView or root LinearLayout of the ScrollView为您的 ScrollView 或 ScrollView 的根 LinearLayout

I now have got a workaround running.我现在有一个解决方法正在运行。 As suggested as I set the textView's backgroundcolor the same as my activity, the arrrows wheren't showing any longer.正如我所建议的那样,我将 textView 的背景颜色设置为与我的活动相同,箭头不再显示。 But the space did behave difrently.但这个空间的行为确实不同。 There it han'd changed somethinf that I changed the backgroundcolor.在那里它已经改变了我改变了背景颜色的东西。 So I just removed it.所以我只是删除了它。 (It still looks kinda good). (看起来还是不错的)。

The updated XML-file od the MainActivity'a content can be seen here:可以在此处看到 MainActivity'a 内容的更新 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="de.jeanma.android.avo.MainActivity"
tools:showIn="@layout/activity_main">
    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:text="Standard text"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:gravity="end"
        android:background="#FAFAFA"/>
    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView">
        <LinearLayout
            android:id="@+id/layout"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:divider="@drawable/divider"
            android:showDividers="middle">
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

But because the arrows were showing threw the padding as well, I changed my但是因为箭头显示也抛出了填充物,所以我改变了我的

src\\main\\res\\values\\dimens.xml to the following (I know that that's really bad practice): src\\main\\res\\values\\dimens.xml到以下内容(我知道这是非常糟糕的做法):

<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">0dp</dimen><!-- This was changed from 16dp to 0dp -->
    <dimen name="fab_margin">16dp</dimen>
</resources>

Thanks @ScriptKity @Wukash @Bryan for your support感谢@ScriptKity @Wukash @Bryan 的支持

在父布局中设置背景颜色。

    android:background="@color/white"

I've run into this problem recently, and believe this is a bug in the hardware accelerated rendering on Android when you combine ScrollView and Spinner.我最近遇到了这个问题,我相信这是当你结合 ScrollView 和 Spinner 时在 Android 上的硬件加速渲染中的一个错误。

I was able to fix this by turning the hardware acceleration off for the Spinner(s):我能够通过关闭微调器的硬件加速来解决这个问题:

mySpinner.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

Other possibilities how to control the hardware acceleration are described here:此处描述了如何控制硬件加速的其他可能性:

https://developer.android.com/guide/topics/graphics/hardware-accel https://developer.android.com/guide/topics/graphics/hardware-accel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM