解决安卓line-height偏上

前段时间遇到问题line-height设置了居中但是却没有出现理想的情况,在安卓中整体的内容偏上,那么只好各种渠道去解决最后有了自己的答案总结一下

首先说一下谷歌浏览器的font-size值的最小值为12px,如果小于12px的时候那么它还是按照12px来显示

那么在安卓也是按照12px来显示,并且当你的块为12px以下的时候才会产生line-height值作用不理想的问题

具体为什么小于12px就会在安卓中导致这个问题我也没找到原因,如果有人知道可以告知我

那么解决办法分为两种

一种自然可以用最舒服scale的办法让字体放大二倍然后居中那么是可以解决这个问题的

而第二种我用flex去解决它的居中就是line-height居中有兼容性,那我们直接不用line-height用flex去让字体居中就好了

老规矩上代码

<!DOCTYPE html>
<html>
<head>
	<title>demo exame</title>
	<style type="text/css">
		.box{
			position: relative;
			width: 200px;
			height: 20px;
			font-size: 2px;
/*			line-height: 20px;*/
			background-color: gray;
			color: white;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	</style>
</head>
<body>
	<div class="box">
		你好
	</div>
</body>
</html>

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
解决 Android 的 TextView 上下空白较大的方法有以下几种: 1. 设置行高(line height):可以通过在 XML 中设置 TextView 的行高来调整上下空白的大小。例如: ``` <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:lineHeight="20dp" android:text="Hello World!" /> ``` 2. 设置 padding 值:可以通过在 XML 中设置 TextView 的 padding 值来调整上下空白的大小。例如: ``` <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="5dp" android:paddingBottom="5dp" android:text="Hello World!" /> ``` 3. 调整字体大小(text size):可以通过在 XML 中设置 TextView 的字体大小来调整上下空白的大小。例如: ``` <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" android:text="Hello World!" /> ``` 4. 调整布局属性(layout attributes):可以通过在 XML 中设置 TextView 的布局属性来调整上下空白的大小。例如,如果 TextView 是在 LinearLayout 中,可以设置 layout_gravity 属性来调整上下位置。例如: ``` <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:layout_gravity="center_vertical" /> </LinearLayout> ``` 希望这些方法可以帮助你解决问题!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值