非常簡單地說,我想根據它的中心而不是它的邊框來對齊 textView,所以讓我們說,當使用 android:layout_marginRight="50dp" 時,而不是右邊框是 50dp,textView 的中心是 50dp從父母的右邊界。這是我的代碼供參考:
<RelativeLayout
android:id="@ id/breakfastStats"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@ id/breakfastAdd"
android:layout_marginTop="1dp"
android:background="@color/lightblack">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Carbohydrate"
android:textColor="@color/white"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:gravity="center"
android:layout_marginTop="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fat"
android:textColor="@color/white"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
/>

uj5u.com熱心網友回復:
通過使用 GridLayout 而不是 RelativeLayout 來修復。
uj5u.com熱心網友回復:
您可以對 TextView 一起使用邊距和填充值。
marginRight = "25dp"
paddingRight = "25dp"
gravity = "center"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/367755.html
標籤:安卓
上一篇:通過片段androidstudio之間的導航傳遞資料
下一篇:在Android中創建復雜的視圖
