i trying create horizontal slider of images fitted in imageview in main layout file. instead of imageview sliding on touch, code moving whole layout horizontally.
following java code sliding:
public class artprofile extends fragmentactivity { static final int num_items = 5; imagefragmentpageradapter imagefragmentpageradapter; viewpager viewpager; public static final string[] image_name = {"a", "b", "c", "d", "e",}; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.fragment_page); imagefragmentpageradapter = new imagefragmentpageradapter(getsupportfragmentmanager()); viewpager = (viewpager) findviewbyid(r.id.pager); viewpager.setadapter(imagefragmentpageradapter); } public static class imagefragmentpageradapter extends fragmentpageradapter { public imagefragmentpageradapter(fragmentmanager fm) { super(fm); } @override public int getcount() { return num_items; } @override public fragment getitem(int position) { swipefragment fragment = new swipefragment(); return swipefragment.newinstance(position); } } public static class swipefragment extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view swipeview = inflater.inflate(r.layout.layoutart, container, false); imageview imageview = (imageview) swipeview.findviewbyid(r.id.image_view1); bundle bundle = getarguments(); int position = bundle.getint("position"); string imagefilename = image_name[position]; int imgresid = getresources().getidentifier(imagefilename, "drawable", "com.example.user.myapplication1"); imageview.setimageresource(imgresid); return swipeview; } static swipefragment newinstance(int position) { swipefragment swipefragment = new swipefragment(); bundle bundle = new bundle(); bundle.putint("position", position); swipefragment.setarguments(bundle); return swipefragment; } } }
following main layout file:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/mobileback" android:layout_width="wrap_content" android:layout_height="wrap_content" > <imageview android:id="@+id/image_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:adjustviewbounds="true" android:maxwidth="150dp" android:maxheight="150dp" android:scaletype="fitcenter" android:layout_marginright="50dp" android:layout_margintop="30dp" android:layout_marginleft="400dp" android:src="@drawable/profilewindow1" android:layout_marginend="58dp" android:layout_alignparenttop="true" android:layout_alignparentend="true" /> <framelayout android:layout_width="match_parent" android:layout_height="330dp" android:layout_alignparentstart="true" android:maxwidth="150dp" android:maxheight="150dp" android:layout_below="@+id/image_view" android:id="@+id/layout_mobile1"> <imageview android:id="@+id/image_view1" android:layout_width="match_parent" android:layout_height="match_parent" /> </framelayout> </relativelayout>
and fragment layout used sliding:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v4.view.viewpager>
i dont understand problem. kindly help. in advance
you can use layout wrap imageview , wrap layout in horizontal scrollview
Comments
Post a Comment