Show video view clearly at the time of scrolling the screen? - android

With in scroll view I have added LinearLayout. That linear layout contains textView ,Video view and etc.. At the time of video palying if I scroll the screen video view flips continuously and the video views old position showing the black color background.
Here is my code.
ScrollView scrl = new ScrollView(context);
scrl.setBackgroundColor(Color.WHITE);
LinearLayout llay = new LinearLayout(context);
llay.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(context);
tv.setText("before VideoView");
tv.setWidth(100);
tv.setHeight(100);
llay.addView(tv);
VideoView video = new VideoView(context);
video.setLayoutParams(new LinearLayout.LayoutParams(200, 150));
video.setVideoPath("/sdcard/test.mp4");
video.start();
llay.addView(video);
TextView tv1 = new TextView(context);
tv1.setTextColor(Color.RED);
tv1.setText("After VideoView");
tv1.setWidth(400);
tv1.setHeight(500);
llay.addView(tv1);
scrl.addView(llay);
setContentView(scrl);
How to show the video view properly at the time of scrolling the screen??
Thanks in advance..

I managed to fix this by setting the background of the VideoView to transparent:
video.setBackgroundResource(android.R.color.transparent);
The video is still flickering while scrolling, but the black box is gone.

Related

Android right aligned LinearLayout strange animations on layout change

I have a right aligned linearlayout attached to a window (I am using a service)
LinearLayout ll = new LinearLayout(this);
llp = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE);
llp.gravity = Gravity.RIGHT;
windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
windowManager.addView(ll, llp);
It has two elements in it: an ImageView and a TextView.
LinearLayout.LayoutParams textParam = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, fixedHeight);
textView = new TextView(this);
ll.addView(textView, textParam);
LinearLayout.LayoutParams imageParam = new LinearLayout.LayoutParams(fixedWidth, fixedHeight);
imageView = new ImageView(this);
ll.addView(imageView, imageParam);
This all works as expected, and image is on the far right and a text snippet is to the left of the image. However after a set amount of time I hide the text snippet.
textView.setVisibility(View.GONE);
I would have thought doing so would have no effect on the imageView as the imageView is on the far right.
However it appears there is some sort of built in animation on layoutchanges which makes the imageview jump to the left most point of the linearlayout and animate back to its original position.
Does anyone know how to disable that animation? I have looked into it and thought something like this would do it:
ll.setLayoutTransition(null);
But it has no effect. I also found this suggestion:
LayoutTransition lt = new LayoutTransition();
lt.disableTransitionType(LayoutTransition.DISAPPEARING);
mContainerView.setLayoutTransition(lt);
That changed the animation actually making it a bit worse for my case.
If anyone has any information on how to disable all layoutchange animations or even any information on them it would be much appreciated.

Bottom part not display in linear layout using scrollview

I have linear layout but bottom part not display if scrolling data is more then screen size.
Streaching Bottom Part when Using Scrollview inside the linearlayout, when scrolling data more then height of the device height.
If i have less data then vertical screen size then all button of bottom appears correctly.
public class TestGUI extends LinearLayout {
sv = new ScrollView(context);
hsv = new HorizontalScrollView(context);
this.addView(topLinearHorizonal);
hsv.addView(tableLayout);
sv.addView(hsv);
this.addView(sv);
this.addView(fullbottomLinearHorizonal);
}
Edited:
LinearLayout fullbottomLinearHorizonal= new LinearLayout(context);
fullbottomLinearHorizonal.setOrientation(VERTICAL);
fullbottomLinearHorizonal.addView(clearLinearHorizonal);
fullbottomLinearHorizonal.addView(bottomLinearHorizonal);
If you want to show fullbottomLinearHorizonal always at the bottom(visible) you can try below while adding views to TestGUI:
LinearLayout.LayoutParams svParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1);
this.addView(sv, svParams);
LinearLayout.LayoutParams fullbottomParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, WRAP_CONTENT);
this.addView(fullbottomLinearHorizonal, fullbottomParams);
Edit: Also default orientation for LinearLayout is horizontal. See link.
You should better set it vertical at TestGUI:
this.setOrientation(VERTICAL);
If you want fullbottomLinearHorizonal at the end of the scroll content then you must add it inside of the scrollView.

Android VideoView: video goes black after being removed from parent view

I am currently playing an rtsp live streaming source using a VideoView. This works fine.
The VideoView is initially inside a fragment with other elements, in 'normal' state, and I am trying to implement a fullscreen toggle button.
To go to fullscreen mode, I am removing the VideoView from its parent (a LinearLayout), and then adding it to another LinearLayout, added on top of everything else using getActivity().addContentView(), here's the code:
LayoutInflater lf = getActivity().getLayoutInflater();
vFullScreen = lf.inflate(R.layout.full_screen, myViewGroup, false);
LinearLayout fullscreenCont = (LinearLayout) vFullScreen.findViewById(R.id.fullscreen_container);
((ViewGroup) vsPlayer.getParent()).removeView(vsPlayer);
fullscreenCont.addView(vsPlayer);
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
getActivity().addContentView(vFullScreen, params);
The problem is that the video goes black once it's removed from the original parent view.
What I'm trying to achieve it's to preserve the video instance to avoid having to reconnect/buffer again, but I don't know how to preserve the video playback during this switching of parents, any ideas?
EDIT:
If I suspend the videoView and then resume it, like this:
LayoutInflater lf = getActivity().getLayoutInflater();
vFullScreen = lf.inflate(R.layout.full_screen, myViewGroup, false);
LinearLayout fullscreenCont = (LinearLayout) vFullScreen.findViewById(R.id.fullscreen_container);
vsPlayer.getVideoView().suspend();
((ViewGroup) vsPlayer.getParent()).removeView(vsPlayer);
fullscreenCont.addView(vsPlayer);
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
getActivity().addContentView(vFullScreen, params);
vsPlayer.getVideoView().resume();
the video play is interrupted (goes black for a few noticeable seconds) but then resumes, wich is a lot better, not perfect because it takes too long to resume play.
Another not so good part is that the methods suspend() and resume() of the class VideoView are available from API level 8 and up, and I need to be compatible with API level 7
Is your problem that the VideoView you're using goes black and temporarily lingers in between the switching of the views?
If so, I've been trying to figure out the cause of that issue for a solid week now. I haven't been able to figure out the actual cause, but my workaround does prevent the VideoView from persisting through screen changes:
public void hideVideoView(){
runOnUiThread(new Runnable() {
public void run() {
findViewById(R.id.yourVideoView).setVisibility(View.INVISIBLE);
}
});
}
I'm basically just setting the view to invisible whenever the view gets switched, and if the view is reloaded I just set it back to View.Visible
This probably won´t :) resolve your problem, but you could seek to the position you where at before removing the VideoView:
long progress = vsPlayer.getCurrentPosition();
LayoutInflater lf = getActivity().getLayoutInflater();
vFullScreen = lf.inflate(R.layout.full_screen, myViewGroup, false);
LinearLayout fullscreenCont = (LinearLayout) vFullScreen.findViewById(R.id.fullscreen_container);
((ViewGroup) vsPlayer.getParent()).removeView(vsPlayer);
fullscreenCont.addView(vsPlayer);
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
getActivity().addContentView(vFullScreen, params);
vsPlayer.seekTo(progress);
I actually had the same issue some time ago.. What i ended up doing was to change the layoutparams of the VideoView to match_parent instead of removing it.
mVideoView.getLayoutParams().width = LayoutParams.MATCH_PARENT;
mVideoView.getLayoutParams().height = LayoutParams.MATCH_PARENT;

setting the children of ViewFlipper at centre

I am adding dynamic text view to view flipper like below.
Everything is working perfectly, but how can i center each text view at center of View Flipper, i have looked for the gravity option but i think it doesn't support. As the text view contains different text length i want every text view to be at center of view flipper.
for(int i = 0; i < 10; i++){
TextView tv = new TextView(this);
vf.addView(tv, i);
}
Thanks
I think this may help :
ViewFlipper flipper = new ViewFlipper(this);
TextView textView = new TextView(this);
textView.setGravity(Gravity.CENTER);
textView.setText("Hello World");
flipper.addView(textView);
setContentView(flipper);
Are you talking about gravitiy we can set this way, or a layout gravity you have tried actually?
tv.setGravity(Gravity.CENTER);
Try to set ViewFlippers width in xml as
android:layout_width="wrap_content"
I had an similar problem and this worked fine.
You can do this way,
TextView tv = new TextView(this);
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
param.gravity = Gravity.CENTER;
tv.setLayoutParams(param);
Ok i got the answer, actually you need to add linearlayout to viewflipper then add children to linearlayout with giving gravity parameter to linear layout.

Android - RelativeLayout CENTER_VERTICAL and BELOW issue

I want a TextView on top and a VideoView below it. I want to have the VideoView as center verical and below the TextView. I am using RelativeLayout.
I am trying to do this in code:
RelativeLayout layout = new RelativeLayout(this);
TextView tv = new TextView(this);
tv.setText("Hello");
tv.setGravity(Gravity.RIGHT);
tv.setTextColor(Color.WHITE);
tv.setId(1);
RelativeLayout.LayoutParams one = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
one.addRule(RelativeLayout.ALIGN_PARENT_TOP);
one.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
RelativeLayout.LayoutParams two = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
two.addRule(RelativeLayout.CENTER_VERTICAL);
two.addRule(RelativeLayout.BELOW, 1);
VideoView mVideoView = new VideoView(this);
layout.addView(tv, one);
layout.addView(mVideoView, two);
setContentView(layout);
The VideoView gets placed below the TextView, but the VideoView is not center vertical.
You made your VideoView fill_parent/fill_parent, which gives it the same dimensions as its parent RelativeLayout. If it's as big as the RelativeLayout, centering cannot really work. Also, you cannot have the VideoView be both below the TextView and centered vertically in the parent; it's one or the other. Instead you could center the ViewView and place the TextView above it.

Categories

Resources