繁体   English   中英

保持背景图片的宽高比(android)

[英]keep aspect ratio of background image (android)

我有一个背景图像,应该按高度缩放,但要保持其纵横比。 我尝试了这段代码:

<ImageView
        android:id="@+id/iv_background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/bg" />

这可以在potrait模式下的手机上使用,但是当我在平板电脑(默认风景)上对其进行测试时,它会缩放宽度并在顶部和底部切割图像。 是因为xml代码还是因为风景?

尝试这样的事情:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:scaleType="centerCrop"
        android:src="@drawable/background_image"/> 

    <!-- Your other views -->

</RelativeLayout>

暂无
暂无

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

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