簡體   English   中英

如何使用RelativeLayout在ImageView右側對齊按鈕

[英]How can I use RelativeLayout to align buttons to the right of an ImageView

我正在為一個簡單的相對布局而苦苦掙扎。 應該在左邊有一個圖像,在右邊有一列其他視圖。 垂直對齊是正確的,但是水平對齊使圖像左側的按鈕非常令人費解,即使我要求它們位於右側。
誰能解釋:

  • 為什么會這樣
  • 如何實現我想要的安排。

這是布局xml和屏幕截圖:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/widget51"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

  <ImageView
      android:id="@+id/ivLove"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_alignParentLeft="true"
      android:layout_centerHorizontal="true"
      />

  <TextView
      android:id="@+id/tvDate"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:hint="Image name"
      android:layout_toRightOf="@+id/ivImage"
      />

  <TextView
      android:id="@+id/tvPage"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:hint="Page URL"
      android:layout_below="@+id/tvDate"
      android:layout_toRightOf="@+id/ivImage"
      />

  <Button
      android:id="@+id/btnNext"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Next"
      android:layout_below="@+id/tvPage"
      android:layout_toRightOf="@+id/ivImage"
      />

  <Button
      android:id="@+id/btnPrevious"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Previous"
      android:layout_below="@+id/btnNext"
      android:layout_toRightOf="@+id/ivImage"
      />

</RelativeLayout>

在此處輸入圖片說明

如果您想了解圖像,請參閱Android:使用AsyncTask的簡單HTML解析和圖像下載器

您將這些控件( TextViewButton )放在id為ivImageImageView 右側

但是,您的布局不包含任何具有該ID的ImageView(但具有ivLove的ImageView )。 控件顯示在左側,因為這是RelativeLayout內視圖的默認對接。

嘗試更新您的引用(將每個“ ivImage ”替換為“ ivLove ”。

注意-如果使用Eclipse ,則沒有得到編譯錯誤的原因是,您的項目中某處可能有ImageView帶有android:id="ivImage" 啟用(並可能更新)棉絨將幫助您過濾此類問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM