Image stretching inside ViewPager in Android -
i trying show couple of image in viewpager. images showing fine in landscape mode in portrait mode images stretching.
here activity:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/coloraccent" android:orientation="vertical" tools:context="com.helloexp.builder.builderactivity"> <android.support.v4.view.viewpager android:id="@+id/builder_viewpager" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v4.view.viewpager> <textview android:layout_width="match_parent" android:gravity="center" android:text="swipe change image" android:background="#000" android:textcolor="#fff" android:layout_height="40dp" android:layout_alignparentstart="true" /> <textview android:layout_width="match_parent" android:layout_centerinparent="true" android:text="when 1 door of happiness closes, opens; long @ closed door not see 1 has opened us." android:layout_height="wrap_content" android:id="@+id/textview"/> <linearlayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_alignparentbottom="true" android:layout_alignparentend="true" android:layout_height="wrap_content"> <button android:layout_width="match_parent" android:layout_weight="5" android:text="decoration" android:layout_height="wrap_content"/> <button android:layout_width="match_parent" android:layout_weight="5" android:text="share" android:layout_height="wrap_content"/> </linearlayout> </relativelayout>
here viewpager adapter xml file:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="wrap_content"> <imageview android:id="@+id/backgroundimage" android:layout_width="wrap_content" android:adjustviewbounds="true" android:scaletype="fitcenter" android:background="@drawable/cat_life_big" android:layout_height="match_parent"/> </linearlayout>
finally here adapter code:
public object instantiateitem(viewgroup container, int position) { layoutinflater inflater = (layoutinflater) mcontext.getsystemservice(context.layout_inflater_service); view layoutview = inflater.inflate(r.layout.layout_builder, container, false); container.addview(layoutview); return layoutview; }
see output
portrait - see image stretching here.
landscape
the problem might android:scaletype="fitcenter
try android:scaletype:"center_crop"
, see does.
also android developer, see center
no scalling...and fit_center
based on center
Comments
Post a Comment