我正在使用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;
}
}}
它worked.Thank你。 – jobin