This is my xml .
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/firstLayout"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/secondView"
android:orientation="vertical">
<FrameLayout
android:id="#+id/videoFrame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.videolan.libvlc.util.VLCVideoLayout
android:id="#+id/videoLayout"
android:fitsSystemWindows="false"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/thirdLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/secondView"
android:layout_weight="1"
android:background="#android:color/holo_orange_light"
android:orientation="vertical">
</LinearLayout>
This is my class :
public class WifiActivity extends AppCompatActivity {
private BroadcastReceiver MyReceiver = null;
private static final String url = " rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4";
private LibVLC libVlc;
private MediaPlayer mediaPlayer;
private VLCVideoLayout videoLayout;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
libVlc = new LibVLC(this);
mediaPlayer = new MediaPlayer(libVlc);
videoLayout = findViewById(R.id.videoLayout);
}
#Override
protected void onStart() {
super.onStart();
mediaPlayer.attachViews(videoLayout, null, false, false);
Media media = new Media(libVlc, Uri.parse(url));
media.setHWDecoderEnabled(true, false);
media.addOption(":network-caching=600");
mediaPlayer.setMedia(media);
media.release();
mediaPlayer.play();
}
}
after running this code I am able to show live streaming using the given URL look like this.
I am trying to remove the black bar which is showing in the given image I want to keep it full screen please help me how to achieve this I am unable to find any solution for this.
you are setting layout_height="match_parent" for VLCVideoLayout, so currently it behaves properly, according to written code
if you want different height for this view, then you should calculate it and set for VLCVideoLayout. here is fun fact: this class will re-set its width and height at runtime (check out onAttachedToWindow method), so even when you set some fixed values in XML - these will be overwritten. its made for "some reason" by library authors, so let's don't touch this class, but now we know that VLCVideoLayout will always stretch/fit to parent
so now I would create some parent class for this video view only
<LinearLayout
android:id="#+id/firstLayout"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/secondView"
android:orientation="vertical">
<FrameLayout
android:id="#+id/videoFrame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.videolan.libvlc.util.VLCVideoLayout
android:id="#+id/videoLayout"
android:fitsSystemWindows="false"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</LinearLayout>
now as we know that frame/video will match_parent width then we can measure it by measuring screen. if this video would be packed into some more complicated layout, e.g. some small video frame in corner - you should measure size of this area (which oftenly have fixed width/size in such case)
knowing videoFrame width you can calculate easily height with just multiplying by ratio of video
int scrWidth = getScreenWidth();
FrameLayout frameLayout = findViewById(R.id.videoFrame);
double ratio = 16d/9d; // 16:9
frameLayout.getLayoutParams().height = (int)(scrWidth / ratio);
Related
I've got a CoordinatorLayout, including a LinearLayout as my BottomSheet. There is also a FrameLayout (direct child of the CoordinatorLayout as well).
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/sketchViewGroup"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="#+id/bottomSheet"
android:layout_width="match_parent"
android:layout_height="340dp"
android:background="#drawable/rounded_top"
android:backgroundTint="#color/colorBottomSheetBackground"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="#dimen/bottomSheetPeekHeight"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/bottomSheetPeekHeight"
android:gravity="center_vertical"
android:orientation="horizontal">
<SeekBar
android:id="#+id/fixedPointsSeekBar"
style="#style/Widget.AppCompat.SeekBar.Discrete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:max="10"
android:progress="10" />
</LinearLayout>
</LinearLayout>
I use the Processing.jar libraries to draw stuff on the FrameLayout.
In order to do this I created a Fragment (so called PFragement in Processing) and added it to the FrameLayout via the SupportFragmentManager. The PFragment takes a PApplet as a constructor. In the PApplet the canvas drawing takes place and also the width and the height get defined. Furthermore I sized the PApplet to fill my FrameLayout.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val sketch = Sketch();
sketchViewGroup.post {
sketch.sketchWidth = sketchViewGroup.width
sketch.sketchHeight = sketchViewGroup.height
// this works:
// sketch.sketchWidth = sketchViewGroup.width -1
// sketch.sketchHeight = sketchViewGroup.height -1
supportFragmentManager.beginTransaction().add(sketchViewGroup.id, PFragment(sketch)).commit();
}
}
}
and
public class Sketch extends PApplet {
int sketchWidth = 100;
int sketchHeight = 100;
public void settings() {
size(sketchWidth, sketchHeight);
}
public void setup(){
background(0);
}
}
Now, wired things are happening: When I size the Sketch to exactly the size of my FrameLayout my BottomSheet does not expand properly anymore. But if I subtract one of the size of my sketch everything works as expected. Can someone explain this and tell how to fix this?
sketch.sketchWidth = sketchViewGroup.width
sketch.sketchHeight = sketchViewGroup.height
sketch.sketchWidth = sketchViewGroup.width -1
sketch.sketchHeight = sketchViewGroup.height -1
It looks like the height of your view group is MATCH_PARENT which is -1. When you subtract 1 from that you get -2 which equals WRAP_CONTENT. So I think you are just setting the height of the sketch object to be WRAP_CONTENT?
I have two views on parent Layout those are top and bottom screens and bottom screen having fixed height and its align to parent-bottom and top screen based on content it must be extend and collapse on parent Layout when i tapped on it and bottom screen automatically come down from top screen and i can able to scroll total content on parent Layout can some one help me please
activity_main.layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_view"
android:background="#3143ff" />
<View
android:id="#+id/bottom_view"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary" />
</RelativeLayout>
MainActivity:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View view = findViewById(R.id.view);
final View contentView = findViewById(R.id.content_frame);
view.setOnClickListener(v -> {
final int screenHeight = contentView.getHeight();
ValueAnimator heightAnimator = ValueAnimator.ofInt(view.getHeight(), screenHeight);
heightAnimator.setDuration(1500);
heightAnimator.addUpdateListener(animation -> {
view.getLayoutParams().height = (int) animation.getAnimatedValue();
view.requestLayout();
});
heightAnimator.start();
});
}
}
See FoldingCell for Android for more help.
In your build.gradle()
dependencies{
implementation 'com.ramotion.foldingcell:folding-cell:1.2.2'
}
In you XML layout
<com.ramotion.foldingcell.FoldingCell
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/folding_cell"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--Layout One-->
<!--Layout Two-->
</com.ramotion.foldingcell.FoldingCell>
Almost done! Two steps remain! For correct animation, you need to set up two properties on the root element(s) of your Folding Cell:
android:clipChildren="false"
android:clipToPadding="false"
In your Java class
// get our folding cell
final FoldingCell fc = (FoldingCell) findViewById(R.id.folding_cell);
// attach click listener to folding cell
fc.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
fc.toggle(false);
}
});
I'm currently working on an application in Xamarin.Android.
In this application, I use several ViewPagers, and I never had any problem with it since yesterday.
At the beginning of my app, I got a kind of animated tour, this is a simple activity containing a ViewPager, which uses 4 fragments (each fragment has one video in it) and so we can scroll horizontally to go further on the tour. Below you can see a screenshot of it :
But I have a problem occurring on all android devices which are not on Android 7 (Android 4 and previous are not supported, so my problem occurs only on Android 5 and 6). When I scroll horizontally on this ViewPager, kind of black bars appear on the left and on the right of each video. I suppose this is not happening on Android 7 because the OS manages videos better. Below you have an example :
Here my video is occupying 100% of the screen space, but it happens also when the video is smaller, I reduced the size of one of them to show you :
Those black bars are not fixed, by that I mean they kind of move randomly on the screen while I scroll horizontally. I put the background color of almost everything in white, but it has no effect. I really think this is Android having difficulties while moving a video on the screen, while this video is still being played. But this is so ugly, it provides a bad UX and this is very important to me and my team to be able to fix this problem.
Here you have the code, if it can help you :
animated_tour.axml (the axml for the activity)
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/vp_animated_tour"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white" />
AnimatedTourActivity.cs (the activity class)
[Activity(Label = "AnimatedTourActivity", Theme = "#style/AppTheme")]
public class AnimatedTourActivity : AppCompatActivity
{
public AnimatedTourViewModel Vm
{
get
{
return App.Locator.AnimatedTour;
}
}
private ViewPager _viewPager;
public ViewPager ViewPager
{
get
{
return this._viewPager ?? (this._viewPager = this.FindViewById<ViewPager>(Resource.Id.vp_animated_tour));
}
}
protected override void OnCreate(Bundle savedInstanceState)
{
SetContentView(Resource.Layout.animated_tour);
base.OnCreate(savedInstanceState);
Window.SetFlags(Android.Views.WindowManagerFlags.Fullscreen, Android.Views.WindowManagerFlags.Fullscreen);
// On bloque en mode portrait
RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
this.ViewPager.Adapter = new AnimatedTourAdapter(this.SupportFragmentManager);
if (Android.OS.Build.VERSION.SdkInt <= BuildVersionCodes.Lollipop)
this.ViewPager.OffscreenPageLimit = 1;
else
this.ViewPager.OffscreenPageLimit = 3;
}
}
One of the four AXML files for a fragment containing a video
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white" />
<VideoView
android:id="#+id/vv_animated_tour_2"
android:layout_gravity="center"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</FrameLayout>
<LinearLayout
android:id="#+id/ll_animated_tour_description"
android:layout_marginTop="350dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="23dp"
android:fontFamily="fonts/AvenirLTStd-Book.otf"
android:textColor="#color/general_text_color_grey"
android:text="#string/animated_tour_family_management" />
<TextView
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingRight="33dp"
android:paddingLeft="33dp"
android:textSize="19.5dp"
android:fontFamily="fonts/AvenirLTStd-Book.otf"
android:textColor="#color/animated_tour_description"
android:text="#string/animated_tour_family_management_description" />
</LinearLayout>
<ImageView
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="100dp"
android:background="#drawable/DOTS_2" />
</RelativeLayout>
AnimatedTourFragment.cs (the common fragment class)
public class AnimatedTourFragment : SupportV4.Fragment
{
static AnimatedTourFragment fragment;
private const string TEMPLATED_ANIMATED_TOUR_RESOURCE_ID = "resource_id";
private const string TEMPLATED_ANIMATED_TOUR_VIDEO_RESOURCE_ID = "video_resource_id";
private const string TEMPLATED_ANIMATED_TOUR_NUMBER = "number";
public AnimatedTourFragment()
{
}
public static AnimatedTourFragment NewInstance(int number, int resourceId, int videoResourceId)
{
fragment = new AnimatedTourFragment();
Bundle args = new Bundle();
args.PutInt(TEMPLATED_ANIMATED_TOUR_RESOURCE_ID, resourceId);
args.PutInt(TEMPLATED_ANIMATED_TOUR_NUMBER, number);
args.PutInt(TEMPLATED_ANIMATED_TOUR_VIDEO_RESOURCE_ID, videoResourceId);
fragment.Arguments = args;
return fragment;
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
//return base.OnCreateView(inflater, container, savedInstanceState);
var resourceId = Arguments.GetInt(TEMPLATED_ANIMATED_TOUR_RESOURCE_ID, 0);
var number = Arguments.GetInt(TEMPLATED_ANIMATED_TOUR_NUMBER, 1);
var videoResourceId = Arguments.GetInt(TEMPLATED_ANIMATED_TOUR_VIDEO_RESOURCE_ID, 0);
var view = inflater.Inflate(resourceId, container, false);
var videoViewId = this.Activity.Resources.GetIdentifier(string.Format("vv_animated_tour_{0}", number), "id", this.Activity.PackageName);
var videoView = view.FindViewById<VideoView>(videoViewId);
videoView.SetOnPreparedListener(new VideoLoop());
videoView.SetVideoURI(Android.Net.Uri.Parse("android.resource://" + this.Activity.PackageName + "/" + videoResourceId));
videoView.Start();
var goButton = view.FindViewById<Button>(Resource.Id.bt_animated_tour_go);
goButton?.SetCommand("Click", (this.Activity as AnimatedTourActivity).Vm.NavigateToHomeCommand);
return view;
}
}
public class VideoLoop : Java.Lang.Object, Android.Media.MediaPlayer.IOnPreparedListener
{
public void OnPrepared(MediaPlayer mp)
{
mp.Looping = true;
}
}
Thanks for your help !
VideoView extends SurfaceView, the main limitation of SurfaceView is that it's not ideal for translation, animation, and moving, this can cause your problem.
What you need is a TextureView based video player. You can try to search for third-party lib.
Or you may try to create such one by yourself, here is some Java resources you may refer to:
Playing video on TextureView
TextureVideoView.java.
I'm trying to find the center coordinates of a RelativeLayout that for the moment, is empty. I need to find the center before I can put anything into the Relative Layout. The Relative Layout is not the whole screen, so I can't use metrics to find the screen dimensions. Since my minimum API is 10, I can't use rLayout.getX() or rLayout.getY(). So what I've tried is:
int xScreenInt = gBoard_RL.getWidth()/2;
int yScreenInt = gBoard_RL.getHeight()/2;
int xInt = gBoard_RL.getLeft() + xScreenInt;
int yInt = gBoard_RL.getTop() + yScreenInt;
and all I get is 0,0. Does anyone have an any ideas how I can get this done? Here's my layout and the Activity so far:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/gb1_root_RL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context=".GB1" >
<RelativeLayout
android:id="#+id/gb1_topInfo_RL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/blu_grade_bg"
android:orientation="vertical"
android:paddingBottom="15dp" >
<TextView
android:id="#+id/gb1_scValue_TV"
style="#style/mainScoreValueStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/gb1_score_TV"
android:layout_marginLeft="10dp" />
<TextView
android:id="#+id/gb1_timeValue_TV"
style="#style/mainTimeValueStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/gb1_time_TV"
android:layout_marginRight="10dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/gb1_gf_RL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/gb1_topInfo_RL"
android:padding="10dp" >
</RelativeLayout>
the Relative Layout I need to find the center of is: android:id="#+id/gb1_gf_RL"
public class GB1 extends Activity {
TextView GScore_TV;
RelativeLayout gBoard_RL;
int xScreenInt, yScreenInt, xInt, yInt;
String xStr, yStr;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.cutin, R.anim.cutout);
setContentView(R.layout.gb_layout);
GScore_TV = (TextView) findViewById(R.id.G1_scoreValue_TV);
gBoard_RL = (RelativeLayout) findViewById(R.id.gb1_gf_RL);
gBoard_RL.setBackgroundColor(Color.MAGENTA);
xScreenInt = gBoard_RL.getWidth()/2;
yScreenInt = gBoard_RL.getHeight()/2;
xInt = gBoard_RL.getLeft() + xScreenInt;
yInt = gBoard_RL.getTop() + yScreenInt;
xStr = String.valueOf(xInt);
yStr = String.valueOf(yInt);
GScore_TV.setText(xStr + ", " + yStr);
}
}
Try putting your code in a onGlobalLayout listener:
myRelativelayout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
this.layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
//Your code here
}
});
EDIT:
Since, as #xorgate pointed out, the layout isnt drawn yet in the onCreate method. The onGlobalLayout method will be called when the layout is drawn and calculations such as yours should be done in there.
onCreate is called before a layout pass is done. All Views will have no size yet.
Try setting a global layout listener, and do the positioning code there.
I have a VerticalViewPager and I have some images in it. When I rotate my device in landscape mode my ImageView doesn't scale to width of my screen. It fits the height if image instead. I used AspectRatioImageView. It fits the width but VerticalViewPager doesn't scroll down.
Thank you.
activity_main.xml:
<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=".MainActivity" >
<HackyViewPager
android:id="#+id/vvp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
>
</HackyViewPager>
</RelativeLayout>
Here is rowitemview.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pixlui="http://schemas.android.com/apk/com.neopixl.pixlui"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#fff" >
<AspectRatioImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="#drawable/m4_3" />
</LinearLayout>
and here is my instaniateItem of my ImagePageAdapter that extends PagerAdapter:
#Override
public Object instantiateItem(ViewGroup container, int position)
{
Context context = MainActivity.this;
container.requestLayout();
AspectRatioImageView imageView = new AspectRatioImageView(context);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.m4_3));
mAttacher = new PhotoViewAttacher(imageView);
mAttacher.setOnMatrixChangeListener(new OnMatrixChangedListener() {
#Override
public void onMatrixChanged(RectF rect) {
if((int)rect.width()>_width)
viewPager.setLocked(true);
else
viewPager.setLocked(false);
}
});
P.S : The issue is with viewPager height. When I scroll down the image it just goes to the other page instead of scrolling the scaled image.
Here's what you need.
This is a good solution I found out.
Android Crop Center of Bitmap
This allows to set the height and your width according to your orientation.
To change the image's scale to full screen, you generally use center crop like this:
yourImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
Hope this information was useful..:)
Use android:scalType = "fitxy" in activity code like this imageView.setScaleType(ImageView.ScaleType.FIT_XY);