微调内部填充是在Android 6.0.1大 [英] Spinner inner padding is larger on Android 6.0.1
问题描述
简介:
使用的Android 6.0.1的新版本,似乎像Android这样做,因为在默认情况下Spinner组件上的一些变化,围绕下来胡萝卜内部填充是有点大了。
With the new release of Android 6.0.1, seems like Android made some changes on the Spinner component because by default, the inner padding around the down carrot is a bit bigger.
我注意到了这一点上,我没有修改在code什么,而只是更新了操作系统的设备上,但微调器有不同的尺寸。一个应用程序
I noticed this on an app where I haven't modified anything in the code, but simply updated the OS on the device and yet the spinners have different sizes.
情况:
我有2个纱厂之一,一个 RelativeLayout的
(介意其他组件,我说的一切,所以你可以看到布局的这部分旁边的另 - 删除在完全不必要的属性或查看IDS)
I have 2 spinners one next to the other in a RelativeLayout
(mind the rest of the components, I added everything so you can see this part of the layout - removed the totally unnecessary properties or view ids)
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/container_for_buttons_on_the_right"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true">
<!-- Buttons here-->
</LinearLayout>
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/spinner_1"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ViewSwitcher
android:id="@+id/spinner_switch"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_toEndOf="@id/spinner_1"
android:layout_toLeftOf="@id/container_for_buttons_on_the_right"
android:layout_toRightOf="@id/spinner_1"
android:layout_toStartOf="@id/container_for_buttons_on_the_right"
android:inAnimation="@anim/fade_in"
android:outAnimation="@anim/fade_out">
<android.support.v7.widget.AppCompatSpinner
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- ImageView properties are incomplete but I need it there.-->
</ViewSwitcher>
</RelativeLayout>
为 getView()
方法使用的微调适配器的布局是这样的:
The layout used by the Spinner adapter for the getView()
method is this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center_vertical"
android:singleLine="true"
tools:text="Test" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0"
android:gravity="center"
android:paddingLeft="4dp"
android:singleLine="true"
android:textColor="@color/text_primary"
android:textSize="@dimen/text_size_body"
tools:ignore="RtlHardcoded,RtlSymmetry"
tools:text="7%" />
</LinearLayout>
为例:
该屏幕截图是结合2个独立的屏幕截图采取:
The screenshot is combined of 2 separate screenshots taken:
- 在顶部的一个采取一个的Nexus 5 设备上运行的的Android 6.0
- 的模式下面也考虑在的Nexus 5 设备,但上运行的的Android 6.0.1
- The one on the top is taken on a Nexus 5 device running on Android 6.0
- The one below is also taken on a Nexus 5 device BUT running on Android 6.0.1
- 修改1
- EDIT 1
从支持库使用AppCompatSpinner不改变行为。用于支持库的版本是 23.1.1
Using AppCompatSpinner from the support library does not change the behaviour. Support library version used is 23.1.1
推荐答案
通过最小的努力,我能够通过建立在微调自定义背景来解决这个问题。
With minimal effort I was able to fix this by building a custom background for the spinner.
使用 AppCompatSpinner
我要创建2个XML为背景,我们称之为 spinner_background.xml
Using AppCompatSpinner
I had to create 2 xmls for the background, let's call this spinner_background.xml
:
1 一人去了绘制
文件夹,看起来像这样, spinner_background.xml
:
1. First one goes to the drawable
folder and looks like this, spinner_background.xml
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="transparent">
<item
android:width="24dp"
android:height="24dp"
android:drawable="@drawable/selector_background_borderless"
android:gravity="end|center_vertical" />
<item android:drawable="@drawable/bg_spinner_anchor" />
</layer-list>
其中, selector_background_borderless
是一个普通的选择就像(我加你所需要的最小的项目,你可以探索它是V21 +纹波的选择。事实上,我会建议你这样做):
Where selector_background_borderless
is a plain selector like(I added the minimal items you need, you could explore it's ripple alternative for v21+. In fact I would recommend you to do so):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#19000000" android:state_pressed="true" />
<item android:drawable="@android:color/transparent" />
</selector>
和 bg_spinner_anchor
是插入符的9patch PNG。我用这些资产: bg_spinner_anchor
And bg_spinner_anchor
is a 9patch PNG for the caret. I used these assets: bg_spinner_anchor
2 第二个转到绘制-V23
文件夹正确支持纹波和看起来像这样, spinner_background.xml
:
2. The second one goes to the drawable-v23
folder to properly support ripple and looks like this, spinner_background.xml
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingEnd="16dp"
android:paddingLeft="0dp"
android:paddingMode="stack"
android:paddingRight="0dp"
android:paddingStart="0dp">
<item
android:width="24dp"
android:height="24dp"
android:drawable="@drawable/selector_background_borderless"
android:gravity="end|center_vertical" />
<item
android:width="24dp"
android:height="24dp"
android:drawable="@drawable/ic_spinner_caret"
android:gravity="end|center_vertical" />
</layer-list>
其中, ic_spinner_caret
是从Android源$ C $ C看起来像这样使用的载体。您应该添加也添加到您的绘制-V23
文件夹:
Where ic_spinner_caret
is a vector used from the Android source code looking like this. You should add also add this to your drawable-v23
folder:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:pathData="M7,10l5,5,5-5z"
android:fillColor="#524e4a"/>
</vector>
Credits go to alanv from the Android UI toolkit for Guidance!
这篇关于微调内部填充是在Android 6.0.1大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!