I am facing the same problem recently, using setAnchorView (videoView), will fully install the controller under VideoView instead of hovering in the bottom area. My VideoView is one third screen in the upper area, so the controller ultimately covers any view in the VideoView.
The following is the way that I end up doing this without creating a full-blown user controller (only overriding onSizeChanged MediaController to move the anchor):
Use FrameLayout as a binding for MediaContoller, wrap it along with VideoView, as shown below:
<RelativeLayout android:id="@+id/videoLayout" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1.3" android:layout_gravity="center" android:background="#000000"> <VideoView android:id="@+id/videoView1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerInParent="true" /> <FrameLayout android:id="@+id/controllerAnchor" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" /> </RelativeLayout>
Create your own MediaController that will move the FrameLayout up (with the MediaController attached to it when it changes):
public class MyMediaController extends MediaController { private FrameLayout anchorView; public MyMediaController(Context context, FrameLayout anchorView) { super(context); this.anchorView = anchorView; } @Override protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld) { super.onSizeChanged(xNew, yNew, xOld, yOld); RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) anchorView.getLayoutParams(); lp.setMargins(0, 0, 0, yNew); anchorView.setLayoutParams(lp); anchorView.requestLayout(); } }
Use the special controller above instead of the standard one, and then bind it to FrameLayout:
protected void onCreate(Bundle savedInstanceState) {
Hafiz Dec 04 '13 at 10:29 2013-12-04 10:29
source share