繁体   English   中英

在小型LinearLayout中对齐TextView Center

[英]Aligning TextView Center in a small LinearLayout

这似乎是一个微不足道的问题,但是我发现以较小的布局对齐TextView是一件痛苦的事情。 这是xml:

 <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_bg_phone" android:gravity="center_vertical" android:orientation="horizontal"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon_phone" /> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="4dp" android:shadowColor="#88FFFFFF" android:shadowDx="0" android:shadowDy="1" android:shadowRadius="0.2" android:textColor="#6d5013" android:textSize="24sp" /> </LinearLayout> 

背景图像是9patch,因此有填充,但是文本未居中并被剪切。 我会发布一个输出图像,但显然这被视为垃圾邮件。 我已经尝试了多种方法,但仍然存在。 较小的文本确实可以改善图像的居中,但是只有非常小的文本才能正确居中。 知道为什么吗?

这样尝试

<LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/button_bg_phone">
<TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitCenter"
                android:shadowColor="#88FFFFFF"
                android:shadowDx="0"
                android:shadowDy="1"
                android:shadowRadius="0.2"
                android:textColor="#6d5013"
                android:textSize="24sp" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM