java - How to make ViewPager fullscreen? -
i have viewpager want take full-screen, takes part of it. how can make take full-screen? here's code, notice filled many calls make layout take full-screen, no avail.
walkthrough_activity.xml:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <android.support.v4.view.viewpager android:id="@+id/view_pager" android:layout_width="fill_parent" android:layout_height="fill_parent" android:minwidth="1080dp" android:minheight="1920dp"/> </relativelayout>
walkthrough_single_view.xml:
<?xml version="1.0" encoding="utf-8"?> <imageview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/image_view" android:layout_width="fill_parent" android:layout_height="fill_parent" />
walkthroughactivity.java:
package org.core.game.activities; import org.core.game.log; import android.annotation.suppresslint; import android.app.activity; import android.content.context; import android.graphics.point; import android.os.bundle; import android.support.v4.view.pageradapter; import android.support.v4.view.viewpager; import android.view.display; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.imageview; import android.widget.relativelayout; import android.widget.relativelayout.layoutparams; public class walkthroughactivity extends activity { private static final int max_views = 1; viewpager mviewpager; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.walkthrough_activity); getwindow().setlayout(main.screenwidth, main.screenheight); mviewpager = (viewpager) findviewbyid(r.id.view_pager); mviewpager.setadapter(new walkthroughpageradapter()); mviewpager.setonpagechangelistener(new walkthroughpagechangelistener()); mviewpager.setx(0); mviewpager.sety(0); display display = getwindowmanager().getdefaultdisplay(); point size = new point(); display.getsize(size); int width = size.x; int height = width; layoutparams lp = new layoutparams(width, height); mviewpager.setlayoutparams(lp); } class walkthroughpageradapter extends pageradapter { @override public int getcount() { return max_views; } @override public boolean isviewfromobject(view view, object object) { return view == (view) object; } @suppresslint("inflateparams") @override public object instantiateitem(view container, int position) { log.e("instantiateitem(" + position + ");"); layoutinflater inflater = (layoutinflater) getsystemservice(context.layout_inflater_service); view imageviewcontainer = inflater.inflate(r.layout.walkthrough_single_view, null); imageview imageview = (imageview) imageviewcontainer.findviewbyid(r.id.image_view); imageview.setscaletype(imageview.scaletype.center_crop); imageview.setadjustviewbounds(true); display display = getwindowmanager().getdefaultdisplay(); point size = new point(); display.getsize(size); int width = size.x; int height = width; imageview.setlayoutparams(new viewgroup.layoutparams(width, viewgroup.layoutparams.fill_parent)); relativelayout.layoutparams layoutparams = new relativelayout.layoutparams(1080, 1920); relativelayout.layoutparams layoutparams = new relativelayout.layoutparams(1080, 1920); imageview.setlayoutparams(layoutparams); switch (position) { case 0: imageview.setimageresource(r.drawable.should_be_full_screen); break; } ((viewpager) container).addview(imageviewcontainer, 0); return imageviewcontainer; } @override public void destroyitem(viewgroup container, int position, object object) { ((viewpager) container).removeview((view) object); } } }
and how looks (the image 1080*1920):
edit: want mini tutorial. 1 page images, 1 page movie. think best way?
try this:
int devicewidthinpixels = getresources().getdisplaymetrics().widthpixels; int deviceheightinpixels = getresources().getdisplaymetrics().heightpixels; imageview.getlayoutparams().width = devicewidthinpixels; imageview.getlayoutparams().height = deviceheightinpixels;
also, use viewpager
:
<android.support.v4.view.viewpager android:id="@+id/view_pager" android:layout_width="fill_parent" android:layout_height="fill_parent" />
and imageview
<?xml version="1.0" encoding="utf-8"?> <imageview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/image_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaletype="fitxy" />
Comments
Post a Comment