How to use video as a background in Android - android

I currently developing a small app in android right now, and instead of using an image resource, I wanna use video as the background. Is this possible?

Use layout with videoview as background
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView
android:scrollbars="none"
android:clickable="false"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:fitsSystemWindows="true"
android:id="#+id/videoView"
/>

Related

I want to set my webview under my gridview via xml

I want to set my webview under my gridview via xml. I want to look something like that
But right now its look like this, webview is diagonal to gridview
This is my code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".Contacts"
android:background="#drawable/gradient"
android:orientation="horizontal">
<GridView
android:layout_width="match_parent"
android:layout_height="450dp"
android:numColumns="2"
android:horizontalSpacing="4dp"
android:verticalSpacing="4dp"
android:id="#+id/gridView"
/>
<WebView
android:layout_width="match_parent"
android:layout_height="550dp"
android:layout_marginTop="180dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_below="#+id/gridView"
/>
</LinearLayout>
But i want to set the images from string array. For wxample

Android: How do I access my main layout with an id (which i had provided in xml) in my class?

I basically want to access my layout so that I can move onto the next screen when the user clicks anywhere on the present screen.
this is my xml code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px"
android:id="#+id/hellolayout">
<TextView
android:text="WELCOME!"
android:textSize="50dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.9"
android:id="#+id/textView1"
android:layout_centerHorizontal="true" />
<ImageView
android:src="#drawable/idiotic_smile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:id="#+id/imageView1" />
</LinearLayout>
In the class, 'hellolayout' is not recognized. Is there anything I'm missing to include?
LinearLayout l = FindViewById<LinearLayout> (Resource.Id.hellolayout);
Acessing a layout should be as simple as R.layout.YourLayoutName. To load it use setContentView(R.layout.YourLayoutName).
Better refer to the docs here.

Can I overlap the WebView with an ImageButton?

What I want to create should look like this :
I want it like this because I want the button to cover a part of the content of the webview making it unreachable for the user.
You can do it using FrameLayout as follows...
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Button" />
</FrameLayout>
Yes You can do.for that purpose you have to use relative layout.first you have add webview,then add image button and set gravity bottom to image button.i think this can help you.
<?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:orientation="vertical" >
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dp"
/>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#android:color/darker_gray"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>

Android layout priotity

My xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:visibility="invisible">
<ImageButton
android:id="#+id/video_playback_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<SeekBar
android:id="#+id/seekbar_video"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_below="#id/video_playback_pause" android:clickable=""/>
</RelativeLayout>
<VideoView
android:id="#+id/videoView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" />
</RelativeLayout>
Now whe RelativeLayout and VideoView override.
the VideoView is show, and the RelativeLayout is hidden.
How to make the RelativeLayout on the top of VideoView?
Another problem is why the seekbar did not click?
I find that the priority of layout is decide by establish order?
But the problem of seekbar is still not resolve.
Try this...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" >
<ImageButton
android:id="#+id/video_playback_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<SeekBar
android:id="#+id/seekbar_video"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_below="#+id/video_playback_pause" android:clickable="true"/>
</RelativeLayout>
<VideoView
android:id="#+id/videoView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</LinearLayout>
EDIT:
You can use the visibilty property as below
android:visibility="invisible" // invisible- just invisible the controls not the space
//gone - removes the allocated space too
//visible- shows the control
At run time also you can change
mylayout.setVisibilty(View.GONE)...
When it comes to your seekbar, this could be the possible answer: Set
android:clickable="true"
and in your java code, try putting an Event Listener. For Event Listeners, http://developer.android.com/guide/topics/ui/ui-events.html
When it comes to your layout, you can try using a Linear Layout and then nest a Relative Layout inside it. You might have to change your xml a bit.
Answer for the first part of question.
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true">
The inner relativeLayout's visibility is set to invisible.Remove it.
You have provided android:clickable="" for seekbar. May be thats why its not working.
Remove that and try.
Hope this will help you.

TextView is not Displayed until VideoView start playing

I wrote an android application which has to two views, VideoView above TextView(which is inside a ScrollView), I met a problem that until the VideoView starts playing a video, the TextView is not displayed and I have a blackscreen, and this might take a long time, since the command to start the video is received from a client via RPC. Could someone please help pointing the problem, either by editing main.xml or using code?
My main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<VideoView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/videoview"
/>
<ScrollView
android:id="#+id/ScrollView01"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView
android:layout_width="wrap_content"
android:id="#+id/textview"
android:layout_height="wrap_content"
android:text="Wellcome"
/>
</ScrollView>
</LinearLayout>
And the import in my activity is only:
setContentView(R.layout.main);
i don't think u will have problem in using relative layout like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<VideoView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/videoview"
android:layout_above="#+id/ScrollView01"
/>
<ScrollView
android:id="#+id/ScrollView01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
>
<TextView
android:layout_width="wrap_content"
android:id="#+id/textview"
android:layout_height="wrap_content"
android:text="Wellcome"
/>
</ScrollView>
</RelativeLayout>

Categories

Resources