VideoView full screen even after fixed values in xml (Android 2.2) - fullscreen

I am facing a strange situation in which the VideoView that I have put in XML layout has fixed width/height, but when same runs on Android tablet running 2.2 of screen resolution (460*800), the video always goes to full screen, and the other views of the same XML overlaps the video.
I do not want video to go to full screen, I want it to be of fixed width/height!
Following is the XML layout, any help is welcome.
<?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" >
<ImageView
android:id="#+id/imgRight"
android:layout_width="267px"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<ImageView
android:id="#+id/imgBottom"
android:layout_width="533px"
android:layout_height="153px"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/imgRight" />
<VideoView
android:id="#+id/videoView"
android:layout_width="533px"
android:layout_height="307px"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>
</RelativeLayout>

You can wrap videoview with a relative layout. Set fixed px values to relative layout and change videoview dimensions with fill_parent:
<RelativeLayout
android:layout_width="533px"
android:layout_height="153px"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true">
<VideoView
android:id="#+id/videoView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>

Refer link
Examples of supported video encoding parameters.
SD (Low quality)SD (High quality) HD (Not available on all devices)
Video resolution 176 x 144 px 480 x 360 px 1280 x 720 px
Video resolution Lower quality = 176 x 144 px Higher quality = 480 x 360 px

I later realized that Android 2.2 can only play video in full screen mode..

Related

Confuse about recyclerview and imageview sizes

i'm currently using a recyclerview to display a menu consisting of an image each row.
i've created the image to be 1080 x 300 in order so it can be scale down withouth mutch issue
I can't quit understand what width options to use for the RecyclerView, and for the items layouts and imageview.
I need the image view to be, around 150dp in Height and the With to ocupy the entire screen, just like on the editor
EDIT 1:
Now theres a huge empty space between rows
Use this code for ImageView in layout resource file created by yourself like custom.xml i.e. res/layout/custom.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="wrap_content">
<ImageView
android:id="#+id/imgItem"
android:layout_width="match_parent"
android:layout_height="150dp" />
</RelativeLayout>
Use this code for RecyclerView :
android:width="match_parent"
android:height="match_parent"
Try to change the Scale of Image View to Center Crop or Fit XY
Like This:
android:scaleType="centerCrop"
Use RecyclerView in your default activity like this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible">
<ImageView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:src= "" />
</androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
Note that the height for ImageView is wrap content. This will work fine given that the height of each image is equal

Design looks perfect on phone but so small on tablet - android studio

I made up this xml file for my android project, the design looks perfect on my phone but running it on my tablet makes buttons, images,... look so small, i would love to make their size change according to the device running on.
here's my xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#drawable/background"
android:fitsSystemWindows="true"
tools:context="molfix.dev.molfix.Activities.Bvn.BienvenuActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:background="#91d0f0"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#drawable/toolbar_bvn"
android:scrollbars="none"
app:popupTheme="#style/AppTheme.PopupOverlay"
android:weightSum="1">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<Button
android:layout_width="250dp"
android:layout_height="55dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#drawable/button_inscrip"
android:id="#+id/b_inscrip"
android:layout_marginTop="20dp"
android:layout_below="#+id/b_connex"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="250dp"
android:layout_height="55dp"
android:background="#drawable/button_connex"
android:id="#+id/b_connex"
android:layout_marginTop="151dp"
android:layout_below="#+id/appbar"
android:layout_alignStart="#+id/b_inscrip" />
</RelativeLayout>
You can try scalable dp instead of dp/sp etc. This will adjust the size of views according to device running on.
Dependency:-
compile 'com.intuit.sdp:sdp-android:1.0.2'
Use like this:-
Replace all "10dp" (your dp value) with "dimen/_10sdp" (change according to your dp value) in your xml.
You have to design your xmls for multi screens. For tab supported, you should create layout-sw600dp layout, this will support 7 inch tablets and for 10 inch tablet create layout-sw720dp. After creating those layouts in res folder copy and paste your xmls in that folders and give sizes for views according to your requirement.

Android Keyboard, custom popuplayout in Nougat

i developed a keyboard that works without issue on MM and lower. By the way on Nougat i have a layout issue, check this images to understand better: http://imgur.com/a/IHfeZ.
The 1st image is on Nougat ( the popup isn't showed completely) the 2nd is like appeared on MM ( all the lines are showed correctly ).
I used this xml to customize the popup:
<?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="wrap_content"
android:orientation="horizontal"
android:background="#color/aosp_pressed">
<android.inputmethodservice.KeyboardView
android:layout_gravity="bottom"
android:id="#android:id/keyboardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:keyPreviewLayout="#layout/preview"
android:keyBackground="#drawable/key_background"
android:keyTextColor="#fff"
android:background="#color/aosp_background"
android:keyTextSize="25sp"/>
<ImageButton android:id="#android:id/closeButton"
android:background="#color/aosp_pressed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:clickable="true"
android:src="#drawable/ic_close_black" />
</LinearLayout>
As you can see the issue is caused by the position of the popup that isn't showed outside the keyboard. How can i solve this issue?
Thanks in advance to everyone.
What is your #layout/preview like?
My theory is that in between Android 6 and 7, the time when wrap_content chooses it's size changed.
Before when using
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TextView
android:id="#+id/xxxxx"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</LinearLayout> //PARTIAL CODE!
there were no problems in 6.0. The text view would expand to fit the text and then be centered.
However, in 7, the text gets displayed completely vertically suggesting that the initial LinearLayout was getting set to a width of 0 and not adjusting.
Try playing with the height in your #layout/preview, or in your closeButton. Set them to manual heights and see if things change accordingly!

How to keep the aspect ratio when changing device?

I need to manage my layout with the dp, not with match_parent, or wrap_content.
This is my XML 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="wrap_content"
android:columnCount="1"
android:orientation="vertical"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:background="#drawable/backprova"
android:adjustViewBounds="true"
tools:context="com.example.settingavatar.MyAvatar" >
<!-- layer per categoria A -->
<LinearLayout
android:id="#+id/llyA"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_column="0"
android:layout_marginLeft="110dp"
android:layout_marginTop="126dp"
android:layout_gravity="center_horizontal|top"
android:layout_row="0"
android:orientation="vertical"
android:visibility="visible"
android:background="#drawable/cata1" >
</LinearLayout>
<!--anteprima dell'avatar -->
<ImageView
android:id="#+id/anteprimaAvatar"
android:layout_width="145dp"
android:layout_height="352dp"
android:layout_weight="1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="43dp"
android:layout_marginLeft="0dp"
android:src="#drawable/avatar"
android:adjustViewBounds="true" />
<!-- other things -->
</RelativeLayout>
When I change devices, the LinearLayout and ImageView don't keep the proportions with the background image (only the aspect ratio between them).
I think the problems are height and width layout.
I have the background image file for every drawable_dpi, but the avatar and the cata1 image only for hdpi, could that be the problem?
In case you want to manage the layout just by using dp, try using an absolute layout, because the basis of using relative layout is to avoid maintaining all the views on dp basis..

How to get Android layout_weight to work?

I'm so frustrated with Android's layout scaling/positioning. I can't get the OS to properly "weigh" my layouts. The base layout is a LinearLayout, and the child layouts have weights set correctly. But when it's run, these proportions aren't maintained. Example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#38921c">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="0.1"
android:orientation="vertical"
android:layout_centerVertical="true">
...(views omitted)
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="0.2"
android:orientation="vertical"
android:layout_centerVertical="true">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/zero" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/zero" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="0.7"
android:orientation="vertical"
android:layout_centerVertical="true">
...(views omitted)
</LinearLayout>
</LinearLayout>
When I run this, the screen (tablet and phone) gives way too much space to the second (0.2 weight) layout, and squeezes the layout(s) below into too small a space. What am I missing regarding proper scaling using layout_weight? Thanks.
android:layout_weight is to specify a size ratio between multiple views.
In this case, it seems you have multiple views. After you have decided how many percentage of the screen supposed to be allocated for each views then you can set it.
Example: You want to divide screen into 3 as 2/10, 3/10 and 5/10(half of the screen), then weight in order is 2, 3, 5. (e.g android:layout_weight="2")
Important: To get it work you also have to set the height or width (depending on your orientation) to 0px. Otherwise, all weight measures will be assumed garbage.

Resources