我正在尝试在比率为4/5的适配器中裁剪VideoView,该适配器使用math_parent表示宽度,而wrap_content表示高度。问题是视频始终失真并且高度与父级匹配。这是我的行xml布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
style="@style/RCPostRow"
>
...
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:layout_marginTop="8dp"
>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/postFrameLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="4:5"
>
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
/>
</FrameLayout>
</android.support.constraint.ConstraintLayout>
...
</LinearLayout>
如果我使用ImageView代替带有scaleType = centerCrop的VideoView,它会起作用:
<ImageView
android:id="@+id/postImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@color/grey"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:minHeight="250dp"
/>
此外,如果我将match_parent用作高度(而不是wrap_content),则会自动调整视频使其适合其父级(人像模式),并出现2个白色边距(左右间距)