开发者社区 问答 正文

ImageView的麻烦


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView              
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/wallpaper" />
</RelativeLayout>

的大小@drawable/peetscoffee_wallpaper为640x480,但未水平居中。我怎样才能解决这个问题?

展开
收起
Puppet 2020-01-19 12:01:49 383 分享 版权
1 条回答
写回答
取消 提交回答
  • 尝试用android:gravity="center"或android:layout_gravity="center"代替centerHorizontal="true"。

    但是,我怀疑这对于设置了大小的图像是否会合理地表现wrap_content-您可能希望使用android:scaleType(例如fitCenter)定义某种图像缩放方法并将其设置为fill_parent而不是wrap_content。640x480大于320x480当前实际的Android设备支持。或者只是按比例缩小您正在使用的图像,从而使设备无需完成工作。

    2020-01-19 12:01:59
    赞同 展开评论
问答分类:
问答地址: