Android VideoView as background - android

I would to use a VideView as background in my layout.
So I would to have this videoView fullscreen and I need to add on this view other 'components' like TextView, EditView, ImageView...etc.
This is an example of my code:
<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=".Login"
android:alpha="0.9">
<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:layout_gravity="center"
android:id="#+id/VideoView">
</VideoView>
<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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:alpha="0.9">
<ImageView
android:id="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dip"
android:layout_width="130dp"
android:layout_height="100dp"
android:alpha="0.7"
android:src="#drawable/logoweb"/>
etc...
In this way I can't see the other components... only the video...

Try using FrameLayout.
FrameLayout always places things one on top of the other and always in reference to the upper lefthand corner,you can use something like this to acheive the above result
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<VideoView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/VideoView"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:alpha="0.7"
android:src="#drawable/logoweb"
/>

Related

ImageView displays above the ListView

I have a layout which consists of a ListView and an Image. I want to place the Image above Listview (in top left corner), but on running the app only Listview is visible and Image goes behind the Listview.
I want to show image instead of first item of the list. Any suggestions?
Below is the layout file:
<LinearLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#android:color/background_light"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="100">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/back"
android:id="#+id/back_button"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:focusable="true"
/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoice">
</ListView>
</FrameLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#android:color/background_light"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/back"
android:id="#+id/back_button"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:focusable="true"
/>
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoice">
</ListView>
</LinearLayout>
<LinearLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#android:color/background_light"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="100">
<FrameLayout
android:id="#+id/frameLayoutImagevIew"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/back"
android:id="#+id/back_button"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:focusable="true"
/>
</FrameLayout>
<FrameLayout
android:layout_below="#id/frameLayoutImagevIew"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoice">
</ListView>
</FrameLayout>
</RelativeLayout>
</LinearLayout>
Try to set an elevation value in the ImageView. For example: android:elevation="5dp". This should solve your problem. Hope it helps.
You can use headerview to add the image at the top like
listview.addHeaderView(view);// view which contains that image
Try this.

Fragment gets cut off in TabbedActivity

This is the preview in the designer.
But when I run the app on a device (Galaxy S4 with 5.0.1) the bottom part of the fragment gets cut off.
chat_fragment.xml
<?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">
<ListView
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
android:layout_marginBottom="48dip"
android:background="#1b184b"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dip"
android:layout_alignParentBottom="true"
android:padding="0dp"
android:layout_margin="0dp"
android:background="#753636"
android:orientation="horizontal">
<EditText
android:layout_width="345dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:hint="Send a message"
android:id="#+id/newmsg"
/>
<ImageButton
android:id="#+id/newmsgsend"
android:src="#drawable/ic_send"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:scaleType="fitEnd"
android:backgroundTintMode="multiply"
android:backgroundTint="#400202" />
</LinearLayout>
</RelativeLayout>
Is this because of something that I should handle from the layout of the fragment?
I changed youx xml code. Just little changes . Use this layout
<?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">
<ListView
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
android:background="#1b184b"
android:layout_alignParentTop="true"
android:layout_above="#+id/edit_linear_layout"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dip"
android:layout_alignParentBottom="true"
android:padding="0dp"
android:layout_margin="0dp"
android:background="#753636"
android:orientation="horizontal"
android:id="#+id/edit_linear_layout"
>
<EditText
android:layout_width="345dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:hint="Send a message"
android:id="#+id/newmsg"
/>
<ImageButton
android:id="#+id/newmsgsend"
android:src="#drawable/ic_send"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:scaleType="fitEnd"
android:backgroundTintMode="multiply"
android:backgroundTint="#400202" />
</LinearLayout>
</RelativeLayout>
You can add bottom margin to your bottom most item to resolve the "cut off" issue.
android:layout_marginBottom="50dp"
In your case, change your ImageButton to the following
<ImageButton
android:id="#+id/newmsgsend"
android:src="#drawable/ic_send"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:scaleType="fitEnd"
android:backgroundTintMode="multiply"
android:backgroundTint="#400202"
android:layout_marginBottom="50dp" />

full width button in android layout using xml

i want to create full width button in android using xml.
here is my code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/menu"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="#drawable/manulogo" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="#android:drawable/btn_star_big_on"
android:layout_centerHorizontal="true"
android:layout_marginTop="220dp"
android:text="Drawable left"
/>
</RelativeLayout>
If you want to get rid of 16 dp margin on left and right, you will need to remove the padding properties from main relative layout.
Also, you can't use property orientation with relative layout. That's for Linear layout.
And you should use match_parent instead of fill_parent for better practice:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/menu"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="#drawable/ic_launcher" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="220dp"
android:drawableLeft="#android:drawable/btn_star_big_on"
android:text="Drawable left" />
</RelativeLayout>
This modified code works fine.
Output:
you have do like this
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
parent layout have left and right padding so remove it and Button will be full screen
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/menu"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="#drawable/manulogo" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="#android:drawable/btn_star_big_on"
android:layout_centerHorizontal="true"
android:layout_marginTop="220dp"
android:text="Drawable left"
/>
</RelativeLayout>

vertical centering one view inside a LinearLayout with two views

i would like to force gauge to be centered vertically above llInner...
i just don't seem to be able
instead of llTop using all the available space it is llInner doing it.
thank you
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llTop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#ff0000">
<eu.sextante.speedlimit.Views.GaugeView
android:id="#+id/gauge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<LinearLayout
android:id="#+id/llInner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="bottom|right"
android:gravity="bottom|right"
android:background="#00ff00">
<eu.sextante.speedlimit.Views.LimitView
android:id="#+id/limit"
android:layout_width="wrap_content"
android:layout_height="60dip"
android:background="#0000ff"
android:maxHeight="60dip"
android:maxWidth="60dip"/>
</LinearLayout>
You should use Relative Layout as main layout like this:
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/llInner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="bottom|right"
android:background="#00ff00"
android:gravity="bottom|right"
android:orientation="horizontal" >
<eu.sextante.speedlimit.Views.LimitView
android:id="#+id/limit"
android:layout_width="wrap_content"
android:layout_height="60dip"
android:background="#0000ff"
android:maxHeight="60dip"
android:maxWidth="60dip" />
</LinearLayout>
<your.gaugeview
android:id="#+id/gauge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="dfdg" />
</RelativeLayout>
Hope it helps you.

Positioning ScrollView on screen

I would like to position a ScrollView at a certain part of screen independently of the screen size and resolution. E.g. I would like it to take up the bottom 30% of the space. Above this ScrollView I want to have an image and empty space.
I have tried that by putting all the views into a linear layout and assigning weights, but that doesn't seem to work. Any ideas about the solution?
The layout I have at the moment:
<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">
<ImageView
android:id="#+id/appLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/logo"/>
<ProgressBar
android:id="#+id/progressbar"
android:indeterminate="true"
android:layout_width="50dp"
android:layout_height="50dp"
style="?android:attr/progressBarStyle"
android:indeterminateBehavior="cycle"
android:layout_below="#id/appLogo"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical|center_horizontal"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/appLogo">
<LinearLayout
android:id="#+id/startLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
</LinearLayout>
</ScrollView>
</RelativeLayout>
Inside the ScrollView I have a LinearLayout, which I use to put in TextView and ImageView elements programaticaly.
What I want to achieve is that no no matter the screen size, there would always be visible a maximum of 3 child elements.
What I tried to do:
<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"
android:background="#android:color/black">"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/appLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_weight="70"
android:src="#drawable/logo"/>
<ProgressBar
android:id="#+id/progressbar"
android:indeterminate="true"
android:layout_width="50dp"
android:layout_height="50dp"
style="?android:attr/progressBarStyle"
android:indeterminateBehavior="cycle"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical|center_horizontal"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="30">
<LinearLayout
android:id="#+id/startLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
But the ScrollView only end ups taking even more space and the image on top gets smaller.
I added a linearlayout for imageview and progress bar and gave it 0dp height and 70 weight.
Also notice that parent linearlayout has a weightsum set to 100.
<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"
android:background="#android:color/black">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="70"
android:orientation="vertical">
<ImageView
android:id="#+id/appLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/logo"/>
<ProgressBar
android:id="#+id/progressbar"
android:indeterminate="true"
android:layout_width="50dp"
android:layout_height="50dp"
style="?android:attr/progressBarStyle"
android:indeterminateBehavior="cycle"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical|center_horizontal"/>
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="30">
<LinearLayout
android:id="#+id/startLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
// try this and let me know if any problem i'm done your requirement with linear layout..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal">
<ImageView
android:id="#+id/appLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:layout_weight="0.70">
<ProgressBar
android:id="#+id/progressbar"
android:indeterminate="true"
android:layout_width="50dp"
android:layout_height="50dp"
style="?android:attr/progressBarStyle"
android:indeterminateBehavior="cycle"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.30">
<LinearLayout
android:id="#+id/startLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"/>
</ScrollView>
</LinearLayout>

Categories

Resources