2013-06-20 45 views
0
中的屏幕

我在图库视图中显示了一堆图像。图库图像不适合android

布局,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="center" 
android:orientation="vertical" > 
<Gallery 
    android:id="@+id/gallery1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:spacing="10dip" > 
</Gallery> 

<ImageView 
    android:id="@+id/imgfromWebUrl" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
</ImageView> 
</LinearLayout> 

和加载图像的自定义适配器,

public View getView(int arg0, View paramView, ViewGroup arg2) { 
    Log.d("","custom Adapter5"); 
    View localView; 
    if (paramView == null) { 
     localView = mInflater.inflate(R.layout.property_image_adapter, null); 
    } else { 
     localView = paramView; 
    }  
    ImageView imgfromWebUrl=(ImageView)localView.findViewById(R.id.imgfromWebUrl);   
    Log.d("", "pics[0]: "+pics); 
    imgfromWebUrl.setImageBitmap(pics[arg0]); 
    imgfromWebUrl.setScaleType(ImageView.ScaleType.FIT_XY); 
    imgfromWebUrl.setBackgroundResource(defaultItemBackground); 
    imgfromWebUrl.setLayoutParams(new Gallery.LayoutParams(200, 200)); 
    return imgfromWebUrl; 
} 

目前我的图像显示为,

enter image description here

我的形象适合到屏幕的中心部分。但我想的图像,以适应全屏幕,这样的形象

enter image description here

请帮我! 任何帮助被赞赏!

+0

设置你的layout_width = “match_parent”。 – Riser

+0

你想删除图像周围的空间,或者想要全景图像吗? –

+0

@Rushabh Patel,无论身高如何,我都希望图像适合屏幕宽度! – Mahe

回答

0

问题:

图片是拟合您的画廊PARAMS是固定的200

解决方案的parent.but:

亲切删除该行。

imgfromWebUrl.setLayoutParams(new Gallery.LayoutParams(200, 200)); 

,并在XML这种变化:

<Gallery 
android:id="@+id/gallery1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:spacing="10dip" > 

+0

我删除了这一行,但它导致了这个异常:java.lang.ClassCastException:android.widget.linearlayout $ layoutparams – Mahe

+0

把你的'imageview'和'gallery'放在单独的xml中,然后在'getview里面放大'imageview'的布局'方法 –

0

配置布局参数,像这样:

i.setLayoutParams(new 
Gallery.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, 
WindowManager.LayoutParams.MATCH_PARENT));