我如何对齐文本视图是在中心两台NumberPickers的(垂直)? [英] How do I align text view to be in center (vertically) of two NumberPickers?

查看:179
本文介绍了我如何对齐文本视图是在中心两台NumberPickers的(垂直)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对齐含有一个TextView:二NumberPickers之间,我也喜欢它是对NumberPickers的顶部,使得它不是推的NumberPickers到一边。目前,这是我的XML包含该NumberPickers和TextView的LinearLayout中:

I would like to align a TextView containing ":" between two NumberPickers, I would also like it to be on top of the NumberPickers so that it is not 'pushing' the NumberPickers to the side. Currently this is my XML for the LinearLayout containing the NumberPickers and TextView:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_below="@id/timer">
    <NumberPicker
        android:id="@+id/numberPicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignCenter="@id/numberPicker1"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:id="@+id/textView"
        android:text=":" />

    <NumberPicker
        android:id="@+id/numberPicker2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
</LinearLayout>

这是什么样子在我的IDE的preVIEW:

And this is what it looks like in my IDE's preview:

我真的想结肠垂直所以它们之间没有空格为中心,过度的NumberPickers。任何帮助是极大AP preciated!

I would really like the colon to be centered vertically and 'over' the NumberPickers so there is no white space between them. Any help is greatly appreciated!

编辑:layout_alignCenter我在那里,现在不工作,似乎并没有做任何事情(是的,我把它凭空)

The 'layout_alignCenter' I have in there right now does not work, doesn't seem to do anything (yes, I pulled it out of thin air).

推荐答案

要获得冒号()出现上述(Z-指数)的采摘,不采取空间,布局需要被分层。有几个方法可以做到这一点,但可能最简单的就是

To get the colon (:) to appear above (z-index) the pickers and not take space, the layout needs to be layered. There are a few ways to do this but likely the simplest is

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_below="@id/timer">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <NumberPicker
            android:id="@+id/numberPicker1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

        <NumberPicker
            android:id="@+id/numberPicker2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    </LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:id="@+id/textView"
        android:text=":" />
</FrameLayout>

这是这里值得一提的是,这里假设两个采摘的绝对中心将是两个采摘的视觉中心。我这样说是因为如果曾经有多少采摘(无论平台或自定义),使垂直中心从布局中心偏移的设计,你就会有一个问题,这个的样子。

It's worth noting here that this assumes that the absolute center of the two pickers is going to be the visual center of the two pickers. I say this because if ever there is a design of the number pickers (either platform or custom) that makes the vertical center offset from the layout center, you'll have an issue with the way this looks.

这篇关于我如何对齐文本视图是在中心两台NumberPickers的(垂直)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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