Allow TextView to be off screen

I want my TextView to be removed from the screen horizontally (and also disable horizontal scrollbars), for example:

enter image description here

However, the XML that I have right now causes it to automatically fit into the parent element, for example:

enter image description here

The code

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/parentlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff">

    <TextView
        android:layout_marginTop="30px"
        android:id="@+id/tab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello1"
        android:textColor="#1089F9"
        android:textSize="40sp"
        android:layout_marginLeft="20dp"
        android:layout_marginBottom="5dp"/>

    <TextView
        android:layout_marginTop="30px"
        android:id="@+id/tab2"
        android:layout_toRightOf="@+id/tab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello2"
        android:textColor="#1089F9"
        android:textSize="40sp"
        android:layout_marginLeft="50dp"
        android:layout_marginBottom="5dp"/>

    <TextView
        android:layout_marginTop="30px"
        android:id="@+id/tab3"
        android:layout_toRightOf="@+id/tab2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello3"
        android:textColor="#1089F9"
        android:textSize="40sp"
        android:layout_marginLeft="50dp"
        android:layout_marginBottom="5dp"/>

</RelativeLayout>

How do I change my code to get the layout displayed in the first image ? Just cut the text if it leaves the parent.

EDIT: Tried LinearLayout. He didn't work either

<LinearLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/parentlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    android:orientation="horizontal">

    <TextView
        android:layout_marginTop="30px"
        android:id="@+id/tab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello1"
        android:textColor="#1089F9"
        android:textSize="40sp"
        android:layout_marginLeft="20dp"
        android:layout_marginBottom="5dp"/>

    <TextView
        android:layout_marginTop="30px"
        android:id="@+id/tab2"
        android:layout_toRightOf="@+id/tab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello2"
        android:textColor="#1089F9"
        android:textSize="40sp"
        android:layout_marginLeft="50dp"
        android:layout_marginBottom="5dp"/>

    <TextView
        android:layout_marginTop="30px"
        android:id="@+id/tab3"
        android:layout_toRightOf="@+id/tab2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello3"
        android:textColor="#1089F9"
        android:textSize="40sp"
        android:layout_marginLeft="50dp"
        android:layout_marginBottom="5dp"/>

</LinearLayout>
+4
source share
2 answers

Try using this attribute on your 3 TextView

android:maxLines="1"

After setting maxLines = "1" I got this result

enter image description here

0
source

Just use LinearLayoutinstead RelativeLayoutand set the orientation to horizontal.

edited

    <LinearLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/parentlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/tab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello1"
        android:textColor="#1089F9"
        android:textSize="40sp"
        android:maxLines="1"
        android:layout_marginLeft="20dp"
        android:layout_marginBottom="5dp"/>

    <TextView
        android:layout_marginTop="30px"
        android:id="@+id/tab2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello2"
        android:textColor="#1089F9"
        android:textSize="40sp"
        android:maxLines="1"
        android:layout_marginLeft="50dp"
        android:layout_marginBottom="5dp"/>

    <TextView
        android:layout_marginTop="30px"
        android:id="@+id/tab3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello3"
        android:textColor="#1089F9"
        android:textSize="40sp"
        android:maxLines="1"
        android:layout_marginLeft="50dp"
        android:layout_marginBottom="5dp"/>
</LinearLayout>
0
source

Source: https://habr.com/ru/post/1598606/


All Articles