Установить позицию видео в окне макета ограничений - PullRequest
0 голосов
/ 19 февраля 2020

main_acitivity. xml

<?xml version="1.0" encoding="utf-8"?>
    <!--suppress ALL -->
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black"
        android:id="@+id/main"
        tools:context=".MainActivity"
        android:layout_gravity="center"
        android:gravity="center">

    <VideoView
        android:id="@+id/videoView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        android:gravity="center"
        />
</androidx.constraintlayout.widget.ConstraintLayout>

Затем в java я делаю следующее

vv = (VideoView) findViewById(R.id.videoView1);

ConstraintLayout.LayoutParams pararams = (ConstraintLayout.LayoutParams) vv.getLayoutParams();
int ch=vv.getHeight();
pararams.height = vv.getWidth();

vv.setLayoutParams(pararams);

КАК СДЕЛАТЬ ВЕРТИКАЛЬНО ЦЕНТРАЛЬНЫЙ ЭЛЕМЕНТ ПОСЛЕ ТОГО? Я сделал vv.setY, я сделал поля, я попытался сделать что-то с xml - ничего не работает, видео либо сверху, либо растянуто через все окно

В настоящее время:

enter image description here

Мне нужно:

enter image description here

Ответы [ 3 ]

1 голос
/ 19 февраля 2020

Попробуйте добавить ниже свойства

<VideoView
    android:id="@+id/videoView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"/>

Я надеюсь, что это может помочь вам!

0 голосов
/ 19 февраля 2020

Создайте четыре Руководства, используя макет ограничения с процентом 25% от ТОПа, 25% от НИЖЕ, 25% от ПРАВА, 25% от НИЖЕ и затем создайте свой VIdeoview. Вы можете отрегулировать процент согласно требованию, а затем в соответствии с размером экрана. организуем соответственно.

<VideoView
android:id="@+id/videoView1"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/guidelinetop"
app:layout_constraintBottom_toTopOf="@id/guidelinebottom"
app:layout_constraintLeft_toRightOf="@id/guidelineleft"
app:layout_constraintRight_toLeftOf="@id/guidelineright"/>
0 голосов
/ 19 февраля 2020

Используйте этот код

<?xml version="1.0" encoding="utf-8"?>

    <!--suppress ALL -->
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black"
    android:id="@+id/main"
    tools:context=".MainActivity"
    android:layout_gravity="center"
    android:gravity="center"
   android:background="#000000">

    <VideoView
        android:id="@+id/videoView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        android:gravity="center"
        />
    </androidx.constraintlayout.widget.ConstraintLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...