2014-11-28 23 views
11

Tôi đặt một ImageView và một VideoView trong RelativeLayout. ImageView có thể được thu nhỏ để lấp đầy toàn bộ bố cục theo scaleType="fitXY". Tuy nhiên, không có thuộc tính quy mô tương tự cho VideoView. Nhân tiện, tôi ẩn điều khiển video bằng cách đặt setMediaController(null) và chỉ nội dung video hiển thị. Có thể quy mô VideoView mà không giữ tỷ lệ khung hình không? Đây là ví dụ bố cục.Android VideoView làm cách nào để mở rộng quy mô loại FitView theo quy mô ImageView?

<RelativeLayout 
    android:layout_width="280dp" 
    android:layout_height="200dp"> 

    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/image" 
     android:scaleType="fitXY" /> 

    <VideoView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/video" 
     android:visibility="invisible" 
     android:layout_centerInParent="true" /> 
</RelativeLayout> 
+0

Cố gắng cho chiều rộng và chiều cao tĩnh. –

+0

Nó không hoạt động. Tôi cố gắng đặt '' nhưng nhận được kết quả tỷ lệ co. – Jones

+0

bạn đã thử ans của tôi chưa? –

Trả lời

24

Cố gắng đưa VideoView bên RelativeLayout và thiết lập bên dưới thuộc tính để hiển thị video trên toàn màn hình:

<VideoView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/video" 
    android:visibility="invisible" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true"/> 

Lưu ý: Hãy thiết lập giá trị tầm nhìn dựa trên yêu cầu của bạn.

+0

Nó hoạt động! Cảm ơn bạn đã giúp đỡ. – Jones

+0

@ Jones, Rất vui được giúp bạn. –

+0

Nó hoạt động và đơn giản như vậy: D – godbye

0

cách của tôi là ghi đè lên các phương pháp onMeasure của VideoView

@Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), 
      getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); 
} 
Các vấn đề liên quan