I am using a ViewPager to load images from server using Picasso. I see whitespace below the actual image. When I swipe the area with whitespace the image is swiped. I have set scaleType="fitXy" to stretch to the ImageView's size.Below is the xml layout and code. Please dont mark it as duplicate.I have googled it and the solutions did not help me.
@dimen/viewpager_img=150dp in 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;
}
}}
You should Set match_parent .
Hard-Coded Value causing problem here .
MATCH_PARENT means that the view wants to be as big as its parent, minus the parent's padding .
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/image1"
android:adjustViewBounds="true"
android:scaleType="fitXY"
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With