我有一個ImageView
和TextView
。我想將TextView
放置在圖像視圖下方,但TextView
的中間與ImageView
(沿着水平軸)的中間對齊。如果TextView
中的文字變爲更大或更小的文字,文字的中間始終需要保持與ImageView
的中間對齊。這可能在xml
?Android:在一個元素下面和另一箇中間對齊
回答
是的,你只是希望包含在垂直LinearLayout
具有android:gravity
設置爲center_horizontal
兩個元素。
像這樣:
<?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="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
... >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
... />
</LinearLayout>
由於TextView
的寬度是wrap_content
,並設置其重力不應該是必要的。我會這樣做只是爲了安全(另外,我也可以將寬度設置爲match_parent
)。
這是令人尷尬的,因爲我已經在代碼的另一個地方做到了這一點。不管怎麼說,還是要謝謝你。 – AndroidDev
那麼,它適用於你的目的?如果是解決方案,請考慮將其標記爲正確,以便其他人也可以找到它。 – Eric
你不能馬上標記。你必須等待幾分鐘。耐心。我幾乎總是標記他們。 – AndroidDev
set TextView
android:layout_width="fill_parent"
and set android:gravity="center"
in TextView
。
我認爲這對你有幫助。
感謝
您可以使用RealtiveLayout的如下..
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
... >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<TextView
android:layout_below="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
如果你希望你的TextView是單行的只有以下屬性添加到TextView的
機器人:ellipsezed =「結束」 機器人:單線=「真」
使用給定的佈局,並把它添加到您的任何現有佈局的你造成你想找..
希望這個解釋對你有用..
- 1. 對齊元素到另一個元素
- 2. 在另一個元素邊框上的Android RelativeLayout對齊元素
- 3. 如何將一個元素與另一個元素正下方直接對齊?
- 4. 在另一個元素的子元素下面繪製元素
- 5. 一個接一個對齊html元素
- 6. 在界面生成器中將UItextFields一個在另一個下面對齊
- 7. 如何定位表格單元(td)中的元素,使一個元素左對齊,另一個右對齊?
- 8. 使用flexbox將一個元素對齊頁面左上角和中間的一個元素
- 9. Jquery位置元素一個在另一個下面
- 10. 對齊一個div標籤下面的另一個標籤
- 11. ListView,減少ListView中一個元素和另一個元素之間的空間
- 12. 對齊的LinearLayout元素與另一個的LinearLayout元素
- 13. 如何將元素與另一個與flex對齊的元素對齊?
- 14. SVG元素部分地落在另一個SVG元素下面
- 15. 在下拉菜單中對齊中心的一個元素
- 16. 兩個div元素,一個在中間,另一個在右邊
- 17. 中間對齊在另一個DIV(故障)一個div
- 18. 絕對定位一個元素*在另一個元素內
- 19. 右對齊一列,左對齊另一個,在一個表內
- 20. 如何在android中將文本對齊到另一個下方?
- 21. div對齊在另一個
- 22. 一個元素使另一個元素
- 23. 如何將兩個跨度元素向左對齊,另一個向右對齊?
- 24. 頁面中間兩個div一個在另一個下
- 25. 如何顯示另一個元素下的一個元素?
- 26. 覆蓋下劃線在另一個元素下面的元素下劃線
- 27. 下一個元素對象
- 28. 如何將一個「li」中的「form」元素與另一個「li」對齊?
- 29. 獲取backbone.js中的下一個元素和上一個元素
- 30. 用jQuery顯示一個元素相對於另一個元素
中間中間中間。 –
我認爲這被稱爲中間拼圖! –