2015-04-25 73 views
-1

我有这个xml代码,我想适合一个图像全屏尺寸,我有这个代码,但我dint得到我所需要的。可以帮助我的任何人吗?我是新来的android,任何其他可能的方式来做到这一点?请帮我如何使图像适合屏幕?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"/> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:adjustViewBounds="true" 
    android:scaleType="fitXY" 
    android:id="@+id/imageView" /> 

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
</android.support.v4.view.ViewPager> 




class CustomPagerAdapter extends PagerAdapter { 

Context mContext; 
LayoutInflater mLayoutInflater; 
int[] mResources = { 
     R.drawable.first, 
     R.drawable.second, 
     R.drawable.third, 
     R.drawable.fourth, 
     R.drawable.fifth, 
     R.drawable.sixth 
}; 
+0

我也曾尝试不同的scaleType方法,但它不起作用, – john

+0

**你在哪里设置图片?你忘了'android:src =“@ drawable/your_picture”' –

+0

使用'android:background =“@ drawable/pic”' – Kunu

回答

1

删除此:

android:adjustViewBounds="true" 

它的使用,如果想将ImageView的调整它的界限,以保持其绘制的长宽比。

0

首先,确保您已将图像拉入项目中。之后要与标签

android:src="(name of image)" 

然后取出设置源图像,

android:adjustViewBounds="true" 

这将使Android的拉伸和扭曲您绘制的图像的ImageView的大小合适,而不是维护方面的在ImageView内的比例。

0

adjustViewBounds如果为true将调整其边界以保留其drawable的高宽比。 所以你的图片不会拉伸以适应XY。经过http://developer.android.com/reference/android/widget/ImageView.html#getAdjustViewBounds%28%29

删除此行 机器人:adjustViewBounds = “真”

并添加此 机器人:背景= “@绘制/ yourImage”

+0

请参阅我的编辑 – john

+0

ImageView imageView =(ImageView)findViewById(R.id.imageView); imageView.setImageResource(mResources [position]); imgview.setScaleType(ScaleType.FIT_XY); – David