如何在除平板电脑之外的所有设备上实现此布局

发布于 2024-11-08 17:21:03 字数 1160 浏览 8 评论 0原文

我现在不担心平板电脑,只担心安卓手机。我有一些即付即用的 LG 手机,我用它来进行开发。我有一个框架布局,其中有一个 VideoView 和一个 WebView

我的 XML 文件定义了特定像素的宽度和高度,并且在我的一台设备上进行测试时效果很好。我在另一台屏幕更大的设备上尝试过,它们不像我的手机那样填满窗口。

我想知道如何用视频填充屏幕的上半部分,用图像填充屏幕的下半部分。我尝试将 layout_width 作为 match_parent,但后来我不确定如何定义高度。这是我想在所有设备上实现的布局。

ss

和我的layout.xml

<?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">
    </VideoView>
    <WebView 
        android:id="@+id/slideHolder"
        android:layout_width="320px" 
        android:layout_height="240px"
        android:layout_gravity="bottom">
     </WebView>
</FrameLayout>

显然我不能在这里使用像素量,那么我的选择是什么?谢谢你,我希望我的问题足够清楚。

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.

ss

and my layout.xml

<?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">
    </VideoView>
    <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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很快妥协 2024-11-15 17:21:03

使用垂直线性布局,并为两个视图指定 layout_weight="1"

<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>

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>
尘世孤行 2024-11-15 17:21:03

为什么要使用FrameLayout?这适用于您想要覆盖视图的情况。在这种情况下,一个简单的带有orientation="vertical"的LinearLayout应该可以解决问题。

<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>

Why are you using a FrameLayout? That is meant for when you want to overlay views. In this case a simple LinearLayoutwith 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文