爲ListView
項目我有以下layout
:Android的 - 如何對齊一個TextView文本
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/item_icon_image"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:src="@drawable/m" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Business Name"
android:id="@+id/item_title_text"
android:layout_toRightOf="@+id/item_icon_image"
android:layout_marginLeft="3dp"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_alignTop="@+id/item_icon_image" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Distance"
android:id="@+id/item_distance_text"
android:layout_alignLeft="@+id/item_title_text"
android:layout_alignBottom="@+id/item_icon_image" />
</RelativeLayout>
這是渲染結果:
正如你可以看到有真正的文本和圖像底部之間的差距......我期望文本的底部與圖像的底部完全匹配......所以問題是:如何將文本對齊到底部圖片?
(這也恰好爲頂部的文本,但在頂部,而非)
編輯:
現在我使用:
android:layout_marginBottom="-10dp"
但我想更多的東西自動,一些解決方案,不會依賴於DP或屏幕....但正如評論,這可能是不可能的,因爲View
需要爲字母,如'Y','G'和'J'的空間。 ..bu我希望可以有一些東西可以根據它的內容對齊它,所以如果沒有'g',它不會節省這個空間。
。否則,如果它是靜態的,則可以始終使用'android:layout_marginTop'和'android:layout_marginBottom'來手動移動文本。 – BVB
這對於'y''j''g'是有意義的......但仍然有一個頂部可以完全填充,我嘗試了所有的大寫字母和重音。 – mFeinstein
將ImageView和TextView放在RelativeLayout中。將RelativeLayout高度參數設置爲wrap_content,然後在ImageView和TextView中將android:layout_alignParentBottom設置爲true。別忘了在TextView上使用ImageView id設置android:layout_toLeftOf。 – Varundroid