您可以检查图片,视频视图具有最大宽度,但内容没有。
这是我的代码,如何调整内部视频的大小以避免空白。
main.layout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="@+id/ll_video_or_image"
android:layout_width="match_parent"
android:layout_height="220dp"
android:adjustViewBounds="true"
android:background="#00ffffff"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:scaleType="centerCrop">
<android.support.constraint.ConstraintLayout
android:id="@+id/parentContsraint"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_logo"
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@color/colorPrimary"
app:layout_constraintDimensionRatio="16:9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
活动
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ll_video_or_image.removeAllViews()
val videoView = VideoView(this)
val params = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
ll_video_or_image.addView(videoView,params)
prepareVideo(videoView,video_url)
}
private fun prepareVideo(videoView: VideoView, link: String){
val mc = MediaController(this)
mc.setAnchorView(videoView)
mc.setMediaPlayer(videoView)
val video = Uri.parse(link)
videoView.setMediaController(mc)
videoView.setVideoURI(video)
videoView.start()
// videoView.seekTo(100)
}
答案 0 :(得分:0)
ConstraintLayout正在增长到父级大小。
所以改变
您android:layout_height="220dp"
至LinearLayout
中的android:layout_height="match_parent"