How to add video ads programmatically

How to add a video review with java code to an xml file?

+3
source share
2 answers

Here is the code except what you use RelativeLayoutin your xml layout

RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
    VideoView video = new VideoView(this);
    video.setVideoURI("yourURI");
    video.setLayoutParams(new FrameLayout.LayoutParams(550, 550));
    layout.addView(video);

feel free to nourish me in anything not obvious to you

+4
source

I already used something like this

final LinearLayout lm = (LinearLayout) findViewById(R.id.linearMain);

RelativeLayout rl = new RelativeLayout(this);

ImageView cb1 = new ImageView(this);
cb1.setId(1);
cb1.setImageResource(R.drawable.ic_launcher);

ImageButton cb2 = new ImageButton(this);
cb2.setImageResource(R.drawable.ic_launcher);
cb2.setBackground(null);
cb2.setId(2);

LayoutParams rp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

rp.addRule(RelativeLayout.BELOW, cb1.getId());

cb2.setLayoutParams(rp);

rl.addView(cb1);
rl.addView(cb2);

lm.addView(rl);

And now I want to do the same, but in this code, the one you gave me:

final LinearLayout lm = (LinearLayout) findViewById(R.id.linearMain);

//Create views
RelativeLayout rl = new RelativeLayout(this);

//TEXTVIEW
TextView txv = new TextView(this);
txv.setText("TEEEEEEEEEXT");
txv.setId(1);
//TEXTVIEW

//VIDEOVIEW
VideoView video = new VideoView(this);
video.setId(2);

            video.setVideoPath("http://tgdsrv.dyndns.org/kroosky/uploads/VID_20140128_215547.mp4");

        android.widget.FrameLayout.LayoutParams fl = new FrameLayout.LayoutParams(300, 300);
        video.setLayoutParams(fl);

        //Create video controllers
        MediaController mediacontroller = new MediaController(VideoDynamic.this);
        mediacontroller.setAnchorView(video);

        //Set controllers to video
        video.setMediaController(mediacontroller);
    //VIDEOVIEW     

        rl.addView(txv);
        rl.addView(video);  

        lm.addView(rl);
0
source

All Articles