2017-07-29 111 views
2

我正在使用ViewPager从服务器使用Picasso加载图像。我在实际图像下方看到空白。当我用空格划动区域时,图像被滑动。 我已经设置了scaleType =“fitXy”以扩展到ImageView的size.Below是xml布局和代码。 请不要将它标记为重复。我已经使用它并且解决方案没有帮助我。Android在图像视图中的空白

@扪/ viewpager_img = 150dp在w320dp-xhdpi

amblnce_display.xml:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" 
    android:id="@+id/amblnce_dsp_lyt" 
    > 
<android.support.v4.view.ViewPager 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/viewpager_img" 
     android:id="@+id/pager" 
     > 
     </android.support.v4.view.ViewPager> 

view_pager_lyt.xml:

<?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="wrap_content"> 
<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/viewpager_img" 
    android:id="@+id/image1" 
    android:scaleType="fitXY" 
    /> 
</LinearLayout> 

ImagePagerAdapter.java:

public class ImagePagerAdapter extends PagerAdapter { 
public ImagePagerAdapter(Context context,String ctgry){ 
if (category.equalsIgnoreCase("Ambulance")){ 
      count=AmbulanceDisplayData.getInstance().imagecount(); 
     } 
layoutInflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
} 
@Override 
    public int getCount() { 

     Log.e("Count",Integer.toString(count)); 
     return count; 
    } 
@Override 
    public Object instantiateItem(ViewGroup container, int position) { 
     view=layoutInflater.inflate(R.layout.view_pager_lyt,container,false); 
     linearLayout=(LinearLayout) view.findViewById(R.id.pgr_lyt); 
     imageView=(ImageView) view.findViewById(R.id.image1); 
    if (category.equalsIgnoreCase("Ambulance")) 
     { 
      count= ambulanceDisplayData.getInstance().imagecount(); 
      images =ambulanceDisplayData.getInstance().getArrayList(); 
      if(count!=0) 
      { 
       Log.e("Images", (String) images.get(position)); 
       Picasso.with(context).load("http://abcd.com/xyz/"+(String) images.get(position)) 
         .placeholder(R.drawable.noimage) 
         .fit().into(imageView); 
      } 
     } 
     container.addView(view); 
     return view; 
    } 
    @Override 
    public void destroyItem(ViewGroup container, int position, Object object) { 
     container.removeView((View)object); 
    } 

    @Override 
    public boolean isViewFromObject(View view, Object object) { 

     if(view==object){ 
      return true; 
     } 
     else { 
      return false; 
     } 

    }} 

回答

1

你应该设置match_parent

硬编码值这里引起问题。

MATCH_PARENT意味着该视图的大小必须与它的父代 一样大,减去父代的填充。

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

它worked.Thank你。 – jobin

0

机器人:adjustViewBounds = “真”

<ImageView 
android:layout_width="match_parent" 
android:layout_height="@dimen/viewpager_img" 
android:id="@+id/image1" 
android:adjustViewBounds="true" 
android:scaleType="fitXY" 
/> 
+0

会尝试你的答案 – jobin

+0

好了,试试吧,如果它的工作,除了回答这样的问题将被关闭 – Anil

+0

它并没有帮助我 – jobin