2017-07-29 62 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