[英]ImageViews and TextViews in Relative Layouts
我想知道是否有人可以解釋我遇到的一個小問題。 我正在努力讓我了解RelativeLayouts並掌握以下內容:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#ffffff"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/newsImage"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentLeft="true"
android:background="#ffffff" >
</ImageView>
<TextView
android:id="@+id/newsSubtitle"
android:layout_height="fill_parent"
android:layout_width="200dp"
android:textColor="#0098bf"
android:layout_centerVertical="true"
android:layout_alignRight="@+id/newsImage"
android:textSize="18sp">
</TextView>
<TextView
android:id="@+id/newsId"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="invisible"
android:textSize="0sp" >
</TextView>
</RelativeLayout>
據我了解,在RelativeLayouts中,您可以使用'alignParentLeft =“ true”'將子項與父項(RelativeLayout)對齊,並且可以使用alignRight =“ @ + id / childId”將每個子項與其他子項對齊。 這似乎可以很好地與TextViews一起使用,但是我很難讓ImageViews正常工作-就像它們實際上似乎沒有占據任何空間一樣,因為TextView只是位於圖像的頂部而不是對齊圖片的右邊。
我在這里誤解了什么嗎?RelativeLayouts是否具有對齊圖像/文本組合的其他方式?
使用此代碼。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#ffffff"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/newsImage"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentLeft="true"
android:background="#ffffff" >
</ImageView>
<TextView
android:id="@+id/newsId"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="gone"
android:textSize="0sp" >
</TextView>
<TextView
android:id="@+id/newsSubtitle"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:textColor="#0098bf"
android:textSize="18sp" />
</RelativeLayout>
在您的文本視圖上調用android:layout_below =“ @ id / idofImageView”並將圖像添加到ImageView。
編輯:對不起,您想要它在右邊: android:align_toRightOf="@id/ImagevIEW"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.