How to achieve this layout on all devices excluding tablets
I am not worried about tablets at the moment, just android phones. I have some pay as you go LG phone that I use to develop on. I have a frame layout with a VideoView
and a WebView
in it.
My XML file defined the width and height at specific pixels and that worked fine for testing on my one device. I tried it on another device which had a larger screen and they dont fill the window like on my go phone.
I was wondering how I can fill the top half of the screen with my video and the bottom half with and image. I tried layout_width
as match_parent
, but then I wasn't sure how to define the height. Here is the layout I want to achieve on all devices.
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mobile_vforum_bg"
>
<VideoView
android:id="@+id/vidPlayer"
android:layout_width="320px"
android:layout_height="240px">
</Vi开发者_如何学编程deoView>
<WebView
android:id="@+id/slideHolder"
android:layout_width="320px"
android:layout_height="240px"
android:layout_gravity="bottom">
</WebView>
</FrameLayout>
Obviously I cant use a pixel amount here, so what are my options? Thank you and I hope my question was clear enough.
Use a vertical linearlayout, and specify layout_weight="1"
for both views.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mobile_vforum_bg">
<VideoView
android:id="@+id/vidPlayer"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</VideoView>
<WebView
android:id="@+id/slideHolder"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
</WebView>
</LinearLayout>
Why are you using a FrameLayout
? That is meant for when you want to overlay views. In this case a simple LinearLayout
with orientation="vertical" should do the trick.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mobile_vforum_bg"
>
<VideoView
android:id="@+id/vidPlayer"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</VideoView>
<WebView
android:id="@+id/slideHolder"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
</WebView>
</LinearLayout>
精彩评论