繁体   English   中英

无法将ImageView与RelativeLayout的底部对齐

[英]Unable to align ImageView to bottom of RelativeLayout

我已经阅读了一些有关如何执行此操作的教程,但是无论出于何种原因,我的图像都不会偏离屏幕中心。 忍者图片为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>

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

您使图像当前填充父级。 更改

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

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

尝试这个

  <?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>

尝试改变

<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大小的空间

// 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

暂无
暂无

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

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