[英]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.