¥ 的字体大小和价格的字体大小不一致时,¥和文字不能底部居中

本文介绍了在Android布局中如何解决不同大小文本视图的垂直对齐问题,并提供使用底部居中与基准线居中两种方法的对比示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当两个文字大小不一致时,不能够用底部居中,底部居中也是居中不了的,最终还是

会显示成一上一下的样式。

如下图所示:



<TextView
        android:id="@+id/rmb"
        android:textSize="@dimen/x10s"
        android:layout_marginTop="@dimen/x10"
        android:layout_marginBottom="@dimen/x5"
        android:gravity="center"
        android:text="¥"
        android:textColor="@color/color_goodsdetail_theme"
        android:layout_below="@+id/tv_attr"
        android:layout_toRightOf="@+id/iv_item"
        android:layout_marginLeft="@dimen/x10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_jiage"
        android:text="0.0"
        android:gravity="center"
        android:textSize="@dimen/x15s"
        android:layout_marginLeft="@dimen/x5"
        android:layout_alignBottom="@+id/rmb"
        android:textColor="@color/color_goodsdetail_theme"
        android:layout_toRightOf="@+id/rmb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />



如果要对齐的话,只能用 基准线居中



代码:

<TextView
        android:id="@+id/rmb"
        android:textSize="@dimen/x10s"
        android:layout_marginTop="@dimen/x10"
        android:layout_marginBottom="@dimen/x5"
        android:gravity="center"
        android:text="¥"
        android:textColor="@color/color_goodsdetail_theme"
        android:layout_below="@+id/tv_attr"
        android:layout_toRightOf="@+id/iv_item"
        android:layout_marginLeft="@dimen/x10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_jiage"
        android:text="0.0"
        android:gravity="center"
        android:textSize="@dimen/x15s"
        android:layout_marginLeft="@dimen/x5"
        android:layout_alignBaseline="@+id/rmb"
        android:textColor="@color/color_goodsdetail_theme"
        android:layout_toRightOf="@+id/rmb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值