[英]How to achieve this layout on all devices excluding tablets
我現在不擔心平板電腦,而只擔心Android手機。 當您使用LG手機進行開發時,我需要支付一定的費用。 我有一個帶有VideoView
和WebView
的框架布局。
我的XML文件定義了特定像素的寬度和高度,並且可以很好地在我的一台設備上進行測試。 我在另一台屏幕更大的設備上嘗試過,它們沒有像我的go手機那樣填滿窗口。
我想知道如何用視頻填充屏幕的上半部分,並用和圖像填充下半部分。 我嘗試將layout_width
用作match_parent
,但是后來我不確定如何定義高度。 這是我要在所有設備上實現的布局。
和我的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>
顯然我不能在這里使用像素量,那么我有什么選擇? 謝謝,我希望我的問題很清楚。
使用垂直的線性布局,並為兩個視圖都指定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>
為什么要使用FrameLayout
? 那是當您想要覆蓋視圖時使用的。 在這種情況下,應該使用一個取向為“ 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.