Android的微调:垂直内微调中心的文本 [英] android Spinner: center text vertically within spinner

查看:244
本文介绍了Android的微调:垂直内微调中心的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要这些微调垂直居中文本。我试过这样的东西在微调XML定义:

i need these spinners to vertically center the text. i've tried stuff like this in the Spinner xml definition:

<Spinner
    android:id="@+id/dir_spn"
    android:layout_gravity="center_vertical"
    android:gravity="center_vertical"
    android:layout_weight="1"/>

我试图建立一个自定义下拉布局:

i tried building a custom drop down layout:

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="@style/SpinnerDropDownItem"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee" />

styles.xml:

styles.xml:

<resources>
<style name="SpinnerDropDownItem">
    <item name="android:gravity">center_vertical</item>
    <item name="android:layout_gravity">center_vertical</item>
    <item name="android:textColor">?android:attr/textColorPrimary</item>
    <item name="android:textColorHighlight">#FFFF9200</item>
    <item name="android:textColorHint">?android:attr/textColorHint</item>
    <item name="android:textColorLink">#5C5CFF</item>
    <item name="android:textSize">16sp</item>
    <item name="android:textStyle">normal</item>
</style>
</resources>

适配器下拉集:

adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);

我如何得到微调文字垂直居中?

how do i get the Spinner text to center vertically?

编辑:
它可能是值得一提的是,活动是在清单正是如此主题:

it may be worth mentioning that the Activity is themed in the manifest thusly:

<resources>
<style name="SpeakNSpell" parent="@android:style/Theme">
    <item name="android:minHeight">68sp</item>
</style>
</resources>

这使得至少所有视图68sp高。这是影响微调中的文本呢?

which makes all Views at least 68sp high. is this affecting the text inside the Spinner as well?

推荐答案

重写

您似乎想要垂直居中文本中的项目资源,如下图所示,但你的code例子目标下拉菜单...

You seem to want to center the text vertically in the item resource, shown below, but your code examples targets the dropdown menu...

顶微调是默认的Andr​​oid simple_spinner_item布局,底部是相同的,但有的android:重力=center_vertical添加

The top Spinner is the default android simple_spinner_item layout and the bottom is the same but has android:gravity="center_vertical" added.

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:gravity="center_vertical"
    android:singleLine="true" />

您可以看到,我用你的主题与大了minHeight 。下面是在适配器使用此布局一个基本的例子:

You can see that I used your Theme with the large minHeight. Here is a basic example to use this layout in an Adapter:

Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_item, list);
// set whatever dropdown resource you want
spinner.setAdapter(adapter);

我要现金,选择产品的假设去了,等从画面中心,让我知道,如果你想在哪里做别的事情!

I went with the assumption that you want "CASH", "Select Product", etc from your picture centered, let me know if you where trying to do something else!

这篇关于Android的微调:垂直内微调中心的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆