Текстовое представление в той же строке - PullRequest
0 голосов
/ 13 марта 2020

Я пытаюсь поместить два textView в одну строку, но у меня возникли некоторые проблемы. Это представление сейчас: enter image description here

Я хотел бы указать дату выпуска слева от строки, а страну - справа от той же строки. Я пытался поместить этот блок в линейное расположение, но все идет в левом верхнем углу экрана. Это мой код:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#1f1f1f"
    android:id="@+id/detail_activity"
    tools:context="com.lab.movietime.View.Activity.Activity.Activity.DetailActivity">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="@dimen/_16sdp"
        android:paddingLeft="@dimen/_16sdp"
        android:paddingRight="@dimen/_16sdp"
        tools:context="com.lab.movietime.View.Activity.Activity.Activity.DetailActivity">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/ll1"
            android:orientation="vertical">
            <ImageView
                android:layout_width="@dimen/_80sdp"
                android:layout_height="@dimen/_30sdp"
                android:layout_marginTop="@dimen/_10sdp"
                android:background="@drawable/logoss"
                android:layout_gravity="center"/>

        </LinearLayout>

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/ll1"
            android:layout_marginTop="@dimen/_10sdp"
            android:id="@+id/youtubePlayer"
            android:orientation="vertical" >

            <com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
                android:id="@+id/youtube_player_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:showFullScreenButton="false" />
        </LinearLayout>


        <LinearLayout
            android:id="@+id/container"
            android:layout_below="@id/youtubePlayer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="@dimen/_9sdp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/posterImg"
                android:layout_width="0dp"
                android:layout_height="@dimen/_180sdp"
                android:layout_weight="1"
                android:scaleType="centerCrop"
                android:background="@android:color/darker_gray"/>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/_11sdp"
                android:layout_marginTop="@dimen/_3sdp"
                android:layout_weight="1"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="8dp"
                    android:textColor="#ffffff"
                    android:text="MovieTitle"
                    android:id="@+id/movieTitle"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                    android:textStyle="bold"/>

                <TextView
                    android:id="@+id/genresTextView"
                    android:layout_width="wrap_content"
                    android:textColor="#ffffff"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="8dp"
                    tools:text="Action, Adventure, Science Fiction, Thriller"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="8dp"
                    android:text="Rating"
                    android:textColor="#ffffff"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                    android:textStyle="bold"/>

                <RatingBar
                    android:id="@+id/listitemrating"
                    android:layout_width="236dp"
                    android:layout_height="43dp"
                    android:numStars="5"
                    android:scaleX="0.5"
                    android:scaleY="0.5"
                    android:theme="@style/RatingBar"
                    android:transformPivotX="@dimen/_10sdp"
                    android:transformPivotY="0dp" />

                <Button
                    android:id="@+id/favButton"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="#ffffff"
                    android:background="@drawable/layout_rounded_corner"
                    android:text="Add to watchlist"/>


            </LinearLayout>
        </LinearLayout>

        <!-- BEGINNING BLOCK -->

        <TextView
            android:layout_marginTop="16dp"
            android:id="@+id/releaseDateHeader"
            android:layout_below="@id/container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:textColor="#ffffff"
            android:text="Release Date"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:textStyle="bold"/>

        <TextView
            android:layout_below="@id/releaseDateHeader"
            android:id="@+id/releaseDateTextView"
            android:layout_width="wrap_content"
            android:ellipsize="end"
            android:textColor="#ffffff"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            tools:text="ff"/>

        <TextView
            android:layout_marginTop="16dp"
            android:id="@+id/countryHeader"
            android:layout_below="@id/releaseDateHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:textColor="#ffffff"
            android:text="Country"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:textStyle="bold"/>

        <TextView
            android:layout_below="@id/countryHeader"
            android:id="@+id/countryTextView"
            android:layout_width="wrap_content"
            android:ellipsize="end"
            android:textColor="#ffffff"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            tools:text="ff"/>

        <!-- END OF BLOCK -->


        <TextView
            android:layout_marginTop="16dp"
            android:id="@+id/overviewHeader"
            android:layout_below="@id/countryTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:textColor="#ffffff"
            android:text="Overview"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:textStyle="bold"/>

        <TextView
            android:layout_below="@id/overviewHeader"
            android:id="@+id/overviewTextView"
            android:layout_width="wrap_content"
            android:ellipsize="end"
            android:textColor="#ffffff"
            android:background="@layout/rounded_border_textview"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginLeft="8dp"
            tools:text="Twenty-two years after the events of Jurassic Park, Isla Nublar now features a fully functioning dinosaur theme park, Jurassic World, as originally envisioned by John Hammond. Twenty-two years after the events of Jurassic Park, Isla Nublar now features a fully functioning dinosaur theme park, Jurassic World, as originally envisioned by John Hammond. Twenty-two years after the events of Jurassic Park, Isla Nublar now features a fully functioning dinosaur theme park, Jurassic World, as originally envisioned by John Hammond."/>

        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"/>

    </RelativeLayout>
</ScrollView>

Блок, который я хочу вставить, находится внутри комментария. Это результат, если я создаю линейный макет: enter image description here

Ответы [ 2 ]

1 голос
/ 13 марта 2020

Проверьте это:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#1f1f1f"
    android:id="@+id/detail_activity"
    tools:context="com.lab.movietime.View.Activity.Activity.Activity.DetailActivity">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="@dimen/_16sdp"
        android:paddingLeft="@dimen/_16sdp"
        android:paddingRight="@dimen/_16sdp"
        tools:context="com.lab.movietime.View.Activity.Activity.Activity.DetailActivity">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/ll1"
            android:orientation="vertical">
            <ImageView
                android:layout_width="@dimen/_80sdp"
                android:layout_height="@dimen/_30sdp"
                android:layout_marginTop="@dimen/_10sdp"
                android:background="@drawable/logoss"
                android:layout_gravity="center"/>

        </LinearLayout>

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/ll1"
            android:layout_marginTop="@dimen/_10sdp"
            android:id="@+id/youtubePlayer"
            android:orientation="vertical" >

            <com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
                android:id="@+id/youtube_player_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:showFullScreenButton="false" />
        </LinearLayout>


        <LinearLayout
            android:id="@+id/container"
            android:layout_below="@id/youtubePlayer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="@dimen/_9sdp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/posterImg"
                android:layout_width="0dp"
                android:layout_height="@dimen/_180sdp"
                android:layout_weight="1"
                android:scaleType="centerCrop"
                android:background="@android:color/darker_gray"/>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/_11sdp"
                android:layout_marginTop="@dimen/_3sdp"
                android:layout_weight="1"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="8dp"
                    android:textColor="#ffffff"
                    android:text="MovieTitle"
                    android:id="@+id/movieTitle"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                    android:textStyle="bold"/>

                <TextView
                    android:id="@+id/genresTextView"
                    android:layout_width="wrap_content"
                    android:textColor="#ffffff"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="8dp"
                    tools:text="Action, Adventure, Science Fiction, Thriller"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="8dp"
                    android:text="Rating"
                    android:textColor="#ffffff"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                    android:textStyle="bold"/>

                <RatingBar
                    android:id="@+id/listitemrating"
                    android:layout_width="236dp"
                    android:layout_height="43dp"
                    android:numStars="5"
                    android:scaleX="0.5"
                    android:scaleY="0.5"
                    android:theme="@style/RatingBar"
                    android:transformPivotX="@dimen/_10sdp"
                    android:transformPivotY="0dp" />

                <Button
                    android:id="@+id/favButton"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="#ffffff"
                    android:background="@drawable/layout_rounded_corner"
                    android:text="Add to watchlist"/>


            </LinearLayout>
        </LinearLayout>

        <!-- BEGINNING BLOCK -->

        <LinearLayout
            android:id="@+id/linear"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/container"
            android:weightSum="2">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            >
        <TextView
            android:layout_marginTop="16dp"
            android:id="@+id/releaseDateHeader"
            android:layout_below="@id/container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:textColor="#ffffff"
            android:text="Release Date"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:textStyle="bold"/>

        <TextView
            android:layout_below="@id/releaseDateHeader"
            android:id="@+id/releaseDateTextView"
            android:layout_width="wrap_content"
            android:ellipsize="end"
            android:textColor="#ffffff"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            tools:text="ff"/>

        </RelativeLayout>


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_weight="1">
        <TextView
            android:layout_marginTop="16dp"
            android:id="@+id/countryHeader"
            android:layout_below="@id/releaseDateHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:textColor="#ffffff"
            android:text="Country"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:textStyle="bold"/>

        <TextView
            android:layout_below="@id/countryHeader"
            android:id="@+id/countryTextView"
            android:layout_width="wrap_content"
            android:ellipsize="end"
            android:textColor="#ffffff"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            tools:text="ff"/>
    </RelativeLayout>
        </LinearLayout>
        <!-- END OF BLOCK -->


        <TextView
            android:layout_marginTop="16dp"
            android:id="@+id/overviewHeader"
            android:layout_below="@id/linear"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:textColor="#ffffff"
            android:text="Overview"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:textStyle="bold"/>

        <TextView
            android:layout_below="@id/overviewHeader"
            android:id="@+id/overviewTextView"
            android:layout_width="wrap_content"
            android:ellipsize="end"
            android:textColor="#ffffff"
            android:background="@layout/rounded_border_textview"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginLeft="8dp"
            tools:text="Twenty-two years after the events of Jurassic Park, Isla Nublar now features a fully functioning dinosaur theme park, Jurassic World, as originally envisioned by John Hammond. Twenty-two years after the events of Jurassic Park, Isla Nublar now features a fully functioning dinosaur theme park, Jurassic World, as originally envisioned by John Hammond. Twenty-two years after the events of Jurassic Park, Isla Nublar now features a fully functioning dinosaur theme park, Jurassic World, as originally envisioned by John Hammond."/>

        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"/>

    </RelativeLayout>
</ScrollView>

Я положил block внутрь LinearLayout, а внутри него у вас две RelativeLayout по центру.
Я не убрал ненужные параметры внутри этих 4 TextView, и я назвал LinearLayout "линейный", но это просто косметика c изменения.

1 голос
/ 13 марта 2020

Поместите эти элементы в относительное расположение и установите их как alignpatentend

 <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/container"

        >

        <TextView
            android:layout_marginTop="16dp"
            android:id="@+id/releaseDateHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:textColor="#ffffff"
            android:text="Release Date"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:textStyle="bold"/>

        <TextView
            android:layout_below="@id/releaseDateHeader"
            android:id="@+id/releaseDateTextView"
            android:layout_width="wrap_content"
            android:ellipsize="end"
            android:textColor="#ffffff"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            tools:text="ff"/>

        <TextView
            android:layout_marginTop="16dp"
            android:id="@+id/countryHeader"
            android:layout_alignParentEnd="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:textColor="#ffffff"
            android:text="Country"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:textStyle="bold"/>

        <TextView
            android:layout_below="@id/countryHeader"
            android:id="@+id/countryTextView"
            android:layout_width="wrap_content"
            android:layout_alignParentEnd="true"
            android:ellipsize="end"
            android:textColor="#ffffff"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            tools:text="ff"/>

        <!-- END OF BLOCK -->


        <TextView
            android:layout_marginTop="16dp"
            android:id="@+id/overviewHeader"
            android:layout_below="@id/countryTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:textColor="#ffffff"
            android:text="Overview"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:textStyle="bold"/>

        <TextView
            android:layout_below="@id/overviewHeader"
            android:id="@+id/overviewTextView"
            android:layout_width="wrap_content"
            android:ellipsize="end"
            android:textColor="#ffffff"
            android:background="@layout/rounded_border_textview"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginLeft="8dp"
            tools:text="Twenty-two years after the events of Jurassic Park, Isla Nublar now features a fully functioning dinosaur theme park, Jurassic World, as originally envisioned by John Hammond. Twenty-two years after the events of Jurassic Park, Isla Nublar now features a fully functioning dinosaur theme park, Jurassic World, as originally envisioned by John Hammond. Twenty-two years after the events of Jurassic Park, Isla Nublar now features a fully functioning dinosaur theme park, Jurassic World, as originally envisioned by John Hammond."/>

        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"/>
    </RelativeLayout>
...