4.1.1上的android RelativeLayout

时间:2014-10-13 09:57:14

标签: android android-layout

我创建了简单的UI,它在Intellij Idea中运行良好。 但是当我在HTC ONE X PLUS(Android版本4.1.1)上运行它时,关闭按钮显示错误

这里是image_elem.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/example"
        android:id="@+id/imageView"
        android:layout_gravity="center_horizontal"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"/>

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/close"
        android:id="@+id/closeImage"
        android:layout_alignParentTop="true"
        android:layout_alignEnd="@+id/imageView"/>

</RelativeLayout>

和我的代码

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_elem);
}

它表明了想法 enter image description here

并显示在设备上

(http://joxi.ru/f6E7VIwyTJCTeU5Xj-o)

2 个答案:

答案 0 :(得分:0)

使用android:layout_alignLeft

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/close"
    android:id="@+id/closeImage"
    android:layout_alignParentTop="true"
    android:layout_alignLeft="@+id/imageView"/>

答案 1 :(得分:0)

尝试android:layout_alignRight - Makes the right edge of this view match the right edge of the given anchor view ID.

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/close"
    android:id="@+id/closeImage"
    android:layout_alignParentTop="true"
    android:layout_alignEnd="@+id/imageView"
    android:layout_alignRight="@+id/imageView"/>