java - Change TextureView Size at Runtime -
i working on streaming mp4 textureview app working on. have textureview displaying video need resize match screen size on rotation. after trial , error seems problem textureview cannot made larger containing view. have tried resize container view unable center textureview correctly on screen.
public void onorientationchanged(int orientation) { if(islandscape(orientation)){ mytexture.setrotation(-90); relativelayout.layoutparams params = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content, relativelayout.layoutparams.wrap_content); params.width = height; params.height = (height * 9)/16; params.addrule(relativelayout.center_in_parent, relativelayout.true); mytexture.setlayoutparams(params); mytexture.getlayoutparams().height = (height * 9)/16; mytexture.getlayoutparams().width = height; rl.requestlayout(); rl.invalidate(); rl.recomputeviewattributes(mytexture); log.v("view size", "width tex: " + mytexture.getwidth()); log.v("view size", "height tex: " + mytexture.getheight()); log.v("view size", "width tex parent: " + rl.getwidth()); log.v("view size", "height tex parent : " + rl.getheight()); } <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".myactivity" android:id="@+id/mediaparent" android:layout_centerinparent="true" android:paddingleft="0dp" android:paddingright="0dp" android:paddingtop="0dp" android:paddingbottom="0dp"> <textureview android:layout_width="360dp" android:layout_height="203dp" android:id="@+id/surface" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" /> <button style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="new button" android:id="@+id/button" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" /> </relativelayout>
try link :
http://www.binpress.com/tutorial/video-cropping-with-texture-view/21
private void initview() { mtextureview = (textureview) findviewbyid(r.id.textureview); // surfacetexture available after textureview // attached window , onattachedtowindow() has been invoked. // need use surfacetexturelistener notified when surfacetexture // becomes available. mtextureview.setsurfacetexturelistener(this); framelayout rootview = (framelayout) findviewbyid(r.id.rootview); rootview.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view view, motionevent motionevent) { switch (motionevent.getaction()) { case motionevent.action_up: updatetextureviewsize((int) motionevent.getx(), (int) motionevent.gety()); break; } return true; } }); } private void updatetextureviewsize(int viewwidth, int viewheight) { mtextureview.setlayoutparams(new framelayout.layoutparams(viewwidth, viewheight)); }
Comments
Post a Comment