简体   繁体   English

如何使用RelativeLayout在ImageView右侧对齐按钮

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

I'm struggling with a simple relative layout. 我正在为一个简单的相对布局而苦苦挣扎。 It is supposed to have an image on the left and a column of other views on the right. 应该在左边有一个图像,在右边有一列其他视图。 The vertical alignment is correct but the horizontal alignment is very puzzling with the buttons on the left of the image even though I have asked for them to be on the right. 垂直对齐是正确的,但是水平对齐使图像左侧的按钮非常令人费解,即使我要求它们位于右侧。
Can anyone explain: 谁能解释:

  • why this happens, 为什么会这样
  • how to achieve the arrangement I want. 如何实现我想要的安排。

Here is the layout xml and a screenshot: 这是布局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>

在此处输入图片说明

In case you are wondering about the image see Android : Simple HTML parsing & image downloader using AsyncTask 如果您想了解图像,请参阅Android:使用AsyncTask的简单HTML解析和图像下载器

You are putting those controls ( TextView , Button ) on the right side of the ImageView with id ivImage . 您将这些控件( TextViewButton )放在id为ivImageImageView 右侧

However, your layout does not contain any ImageView with that id (but has one with ivLove ). 但是,您的布局不包含任何具有该ID的ImageView(但具有ivLove的ImageView )。 The controls appear on the left because that's the default docking for views inside a RelativeLayout . 控件显示在左侧,因为这是RelativeLayout内视图的默认对接。

Try updating your references (replace each " ivImage " with " ivLove ". 尝试更新您的引用(将每个“ ivImage ”替换为“ ivLove ”。

Note -- if you use Eclipse , that the reason you didn't get compile errors for this is that you probably have an ImageView with android:id="ivImage" somewhere in your project. 注意-如果使用Eclipse ,则没有得到编译错误的原因是,您的项目中某处可能有ImageView带有android:id="ivImage" Enabling (and maybe updating) lint will help you filter these kinds of issues. 启用(并可能更新)棉绒将帮助您过滤此类问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM