在android TextView中将后缀与标签空间垂直对齐 [英] Vertically aligning suffix with tab space in android TextView

查看:42
本文介绍了在android TextView中将后缀与标签空间垂直对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一行(水平 LinearLayout),最后有一个 TextView 显示时间.这是它的外观:

I have rows (of horizontal LinearLayout) with a TextView at the end that displays time. An this is how it looks:

现在我需要所有行中的后缀 (am/pm) 垂直对齐.上面的布局不是这样,可以看到,最后一行由于显示时间较长而未对齐.

Now I need the suffix (am/pm) in all rows to be aligned vertically. This is not the case in the above layout, as you can see, the last row is misaligned as the displayed time is longer.

我使用制表符 \u0009 实现了这一点.这意味着我会将文本设置为例如7:21\u0009\u0009pm".这会产生如下所示的预期结果:

I achieved this using the tab character \u0009. This means I would set the text to be for example "7:21\u0009\u0009pm". This produces desired result as show below:

但是,我需要知道(1) 这是否是最有效的方法(2) 这是否适用于所有 android 设备.如果有其他方法可以实现这一点,请告诉我.

However, I need to know if (1) this is the most efficient way and (2) that this would work on all android devices. If there is an alternative way to achieve this please let me know.

这里是一行的 XML 布局供您参考:

And here is an XML layout of a row for your reference:

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/prayer_time_row_height"
            android:layout_marginLeft="48dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <com.devspark.robototextview.widget.RobotoTextView
                style="@style/text_subhead"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Today"
                android:textColor="@color/material_light_secondary_text"
                android:visibility="invisible" />

            <com.devspark.robototextview.widget.RobotoTextView
                style="@style/text_subhead"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Event"
                android:textColor="@color/material_light_primary_text" />

            <com.devspark.robototextview.widget.RobotoTextView
                style="@style/text_subhead"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="12:06\u0009\u0009am"
                android:textColor="@color/material_light_primary_text" />

        </LinearLayout>

奖金

指出垂直对齐小时-分钟分隔符(即冒号字符)的方法的加分项.

Bonus points for pointing out a way to vertically align the hour-minute separator, i.e., colon character.

推荐答案

对于冒号字符,您可以尝试使用字符\uee01"代替:".这就是谷歌对锁定屏幕中的时钟所做的.

For the colon character, you could try using the character "\uee01" instead of ":". This is what google does with the clock in the lock screen.

https://github.com/android/platform_frameworks_base/blob/master/packages/Keyguard/src/com/android/keyguard/KeyguardStatusView.java#L247

这篇关于在android TextView中将后缀与标签空间垂直对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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