How to center 02 Textview of Videoview

Asked

Viewed 63 times

0

I have 02 Textview and I want to put them in the center of a Videoview where a text is on top of each other.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <VideoView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/videoView"
        android:layout_gravity="center_horizontal" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="30º C"
        android:layout_gravity="center_horizontal"
        android:textSize="28sp"
        android:id="@+id/Temperatura" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Notícias regionais"
        android:layout_gravity="center_horizontal"
        android:textSize="28sp"
        android:id="@+id/Notícia" />
</LinearLayout>

2 answers

1


You can’t set that in a Linearlayout because of the need to define its orientation. Exchange Linearlayout for a Relativelayout and add attributes to the 2 textViews:

android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"

do as follows:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/videoView" />
<TextView
    android:text="30º C"
    android:textSize="28sp"
    android:id="@+id/Temperatura"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />
<TextView
    android:text="Notícias regionais"
    android:textSize="28sp"
    android:id="@+id/Notícia"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/></RelativeLayout>
  • 1

    In addition, add the android attribute:paddingTop="50dp" in the last Textview so that one text is not on top of the other.

0

You can use Relativelayout and place the attribute in the textview android:layout_centerInParent="true"

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <VideoView
            android:id="@+id/videoView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="text view 1" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="text view 2" />

    </RelativeLayout>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.