我有一個線性佈局(水平),其中包含5個文本視圖。我的目標是在屏幕左側有兩個文字瀏覽,中間有大的空間,然後是剩餘的文字瀏覽。居中佔據空間的視圖線性/重量
就是這樣。
[文本] [文本] [空白] [文本] [文本]
結束這樣。
[文字] [文] [空白] [文] [文]
我能得到這個體重工作,差不多。問題在於文本視圖在其佔據的空間內顯示爲左對齊,我試圖讓顯示的文本居中在其佔據的空間內。
這可能嗎?
我有一個線性佈局(水平),其中包含5個文本視圖。我的目標是在屏幕左側有兩個文字瀏覽,中間有大的空間,然後是剩餘的文字瀏覽。居中佔據空間的視圖線性/重量
就是這樣。
[文本] [文本] [空白] [文本] [文本]
結束這樣。
[文字] [文] [空白] [文] [文]
我能得到這個體重工作,差不多。問題在於文本視圖在其佔據的空間內顯示爲左對齊,我試圖讓顯示的文本居中在其佔據的空間內。
這可能嗎?
,您可以嘗試
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView2"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#f00"></View>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView3"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView4"/>
</LinearLayout>
機器人:textAlignment = 「中心」 做了工作。
欣賞上面的例子。好東西!
嘗試如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="text1"
android:gravity="center_horizontal"
android:layout_weight="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="text2"
android:layout_weight="1"/>
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="text1"
android:layout_weight="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="text3"
android:gravity="center_horizontal"
android:layout_weight="0.66"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="text4"
android:layout_weight="0.66"/>
<TextView
android:layout_width="0dp"
android:gravity="center_horizontal"
android:layout_height="wrap_content"
android:text="text5"
android:layout_weight="0.66"/>
</LinearLayout>
寫的android:單線= 「真」 如果你希望你的TextView一個襯墊。
你可以做到這一點很容易與RelativeLayout的
[文本1] [文本2] [空白] [文字3] [文本4]
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text1" />
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/tv1"
android:text="text2" />
<TextView
android:id="@+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/tv4"
android:text="text3" />
<TextView
android:id="@+id/tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="text4" />
</RelativeLayout>
你試過'機器人:textAlignment =「中心「'? (它需要API 17) – ilya