[英]Android Full Width Video View
我試圖將線性布局內的視頻視圖拉伸到全屏,但它與設備屏幕不匹配。 這是我的代碼
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="720dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_gravity="fill_horizontal"
android:layout_marginTop="140dp" >
<VideoView
android:id="@+id/videoView1"
android:layout_width="fill_parent"
android:layout_height="720dp" />
</LinearLayout>
左右各有 10 到 15 dp 的空間。 此外,線性布局不會拉伸到全屏。 我希望它以寬度填充屏幕。
實際上不需要以編程方式設置寬度
android:layout_width="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
應該足以用全寬視頻視圖填充容器。 並使用 match_parent 而不是 fill_parent。 希望這可以幫助某人。
您可以使用顯示矩陣獲取屏幕的當前高度和寬度
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int h = displaymetrics.heightPixels;
int w = displaymetrics.widthPixels;
現在為您的視頻視圖使用此高度和寬度 :) 以編程方式使用它,而不是像 720dp 之類的硬編碼。 getWidth()
和getHeight()
已被谷歌棄用
獲取布局的運行時高度和寬度,並在VideoView
設置
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
//videoview.setLayoutParams(new FrameLayout.LayoutParams(550,550));
videoview.setLayoutParams(new FrameLayout.LayoutParams(width,height));
//FrameLayout : write your layout name which you used
嘗試在android:layout_height
使用fill_parent
而不是使用特定的高度。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_gravity="fill_horizontal">
<VideoView
android:id="@+id/videoView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.