【问题标题】:keep aspect ratio of background image (android)保持背景图像的纵横比(android)
【发布时间】:2014-09-10 10:11:36
【问题描述】:

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

<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代码还是因为风景?

【问题讨论】:

  • 你试过删除android:scaleType="centerCrop"
  • 是的,那么它在肖像模式下的手机上不起作用
  • 你能给我们看一些屏幕吗?
  • 我用这个 bg 例如:rivello.net/img/bg.jpg 手机:abload.de/img/1t9kx7.png 平板电脑:abload.de/img/3vbjo6.png
  • 你到底想做什么?因为它在我的平板电脑上按预期工作。除非您在顶部/底部或左侧/右侧显示白色条纹,否则图像将始终被剪切

标签: android xml


【解决方案1】:

试试这样的:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多