适合的android形象,以填补整个布局 [英] android fit image to fill whole layout

查看:132
本文介绍了适合的android形象,以填补整个布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了以适应整个屏幕我的测试设备上分辨率的图像。当与其它屏幕尺寸测试,图像只适合宽度或高度并留下一个空的空间,因为它总是缩放比例。我怎么可以设置图像也适合全屏比例是否发生变化?例如,如果我的设备屏幕为3/4,图像将被适当的比例上显示的3/4依赖于它的分辨率。然而,对于一个16/9将不适合全屏。

I have an image that has resolution in order to fit whole screen on my test device. When tested with other screen sizes, image fits only width or height and leaves an empty space because it always scales proportional. How could I set image to fit fullscreen also if proportion changes? For example, if my device screen is 3/4, image will be properly scaled on 3/4 displays independent on its resolution. However, for a 16/9 will not fit fullscreen.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:background="@color/blueish"
  android:layout_height="fill_parent">
    <ImageView 
        android:src="@drawable/splashandroid" 
        android:id="@+id/imageView1" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content">
        </ImageView>


</LinearLayout>

有关图像布局宽度也尝试WRAP_CONTENT

also tried wrap_content for image layout width

推荐答案

在你加入这个ImageView的,的android:scaleType =fitXY或者您可以在您使用此活动方式 imgview.setScaleType(ScaleType.FIT_XY);

Add this in you ImageView, android:scaleType="fitXY" or you can use this in you activity means imgview.setScaleType(ScaleType.FIT_XY);

您可以用这个试试,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:background="@color/blueish"
  android:layout_height="fill_parent">
    <ImageView 
        android:src="@drawable/splashandroid" 
        android:id="@+id/imageView1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:scaleType="fitXY"/>

</LinearLayout>

这篇关于适合的android形象,以填补整个布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆