无法将ImageView与RelativeLayout的底部对齐

时间:2014-05-15 10:52:28

标签: android android-layout

我已经阅读了几个关于如何执行此操作的教程,但无论出于何种原因,我的图像都不会从屏幕中心移开。忍者图像是1080x517px

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:weightSum="1"
              android:background="@color/white">

    <ImageView
        android:id="@+id/ninjas"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/ninjas"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>

据我所知,这是正确的。有什么建议? 提前致谢

4 个答案:

答案 0 :(得分:1)

您可以让图像填充当前的父级。改变

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

答案 1 :(得分:1)

试试这个

  <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff" >

<ImageView
    android:id="@+id/ninjas"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/ic_launcher" />

 </RelativeLayout>

答案 2 :(得分:0)

尝试更改

<ImageView
    android:id="@+id/ninjas"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/ninjas"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"/>

<ImageView
    android:id="@+id/ninjas"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ninjas"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"/>

目前您的ImageView占据了其父级的所有空间。将layout_widthlayout_height更改为wrap_content后,只会占用@drawable/ninjas

大小的空间

答案 3 :(得分:0)

// Try this way,hope this will help you to solve your problem...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:gravity="bottom|right"
    android:padding="5dp">

    <ImageView
        android:id="@+id/ninjas"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ninjas"
        android:adjustViewBounds="true"/>

</LinearLayout
相关问题