简体   繁体   中英

Stop text view from going out of screen

Im trying to make an app in android studio. I have a textview with a circular background. The thing is that when i install it on ta physical device the Text view goes of the screen. Hers the preview in android studio: 在此处输入图像描述

The Xml code:

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

             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="#000000"
>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="55dp"
            android:orientation="horizontal"
            android:background="@drawable/top_bar">

            <TextView
                android:id="@+id/textView3"
                android:layout_width="40dp"
                android:layout_height="match_parent"
                android:layout_weight="0"

           android:drawableLeft="@drawable/ic_keyboard_arrow_left_black_24dp"

                />

            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:fontFamily="@font/segoeui"
                android:gravity="center_vertical|start"
                android:text="App name and image"

                android:textColor="#FFFFFF"
                android:textSize="30dp" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textView6"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fontFamily="@font/segoeui"
                android:gravity="center"
                android:text="Pakistan vs Australia T20"
                android:textColor="#ffff"
                android:textSize="24dp" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="1.5dp"
            android:background="#ffff"
            android:orientation="vertical"
            android:layout_marginLeft="47dp"
            android:layout_marginRight="47dp"></LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="300dp"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="247dp"
                android:layout_height="match_parent"
                android:orientation="vertical">


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="40dp"
                    android:gravity="center"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/textView2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:fontFamily="@font/segoeui"
                        android:gravity="center"
                        android:text="Match Odds"
                        android:textColor="#ffff"
                        android:textSize="17dp" />

                    <TextView
                        android:id="@+id/textView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:fontFamily="@font/segoeui"
                        android:paddingLeft="10dp"
                        android:text="Favourite"
                        android:textColor="#ffff"
                        android:textSize="17dp" />
                </LinearLayout>


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:layout_marginTop="30dp"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/textView12"
                            android:layout_width="40dp"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text="0"
                            android:textColor="#ffff"
                            android:textSize="20dp"
                            android:textStyle="bold" />

                        <TextView
                            android:id="@+id/textView11"
                            android:layout_width="20dp"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text="-"
                            android:textColor="#ffff"
                            android:textSize="20dp"
                            android:textStyle="bold" />

                        <TextView
                            android:id="@+id/textView10"
                            android:layout_width="40dp"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text="0"
                            android:textColor="#ffff"
                            android:textSize="20dp"
                            android:textStyle="bold" />
                    </LinearLayout>


                    <TextView
                        android:id="@+id/textView13"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="40dp"
                        android:layout_marginTop="30dp"
                        android:fontFamily="@font/segoeui"
                        android:gravity="center"
                        android:text="WestIndies"
                        android:textColor="#ffff"
                        android:textSize="16dp"


                        android:visibility="visible" />


                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/textView4"
                        android:layout_width="100dp"
                        android:layout_height="1dp"
                        android:layout_marginLeft="6dp"

                        android:background="@color/margins"
                        android:text="TextView" />

                    <TextView
                        android:id="@+id/textView7"
                        android:layout_width="100dp"
                        android:layout_height="1dp"
                        android:layout_marginLeft="30dp"
                        android:background="@color/margins"
                        android:text="TextView" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/textView9"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:fontFamily="@font/segoeui"
                        android:gravity="center"
                        android:text="Session"
                        android:textColor="#ffff"
                        android:textSize="17dp" />

                    <TextView
                        android:id="@+id/textView8"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:fontFamily="@font/segoeui"
                        android:gravity="center"
                        android:text="Runs/Balls"
                        android:textColor="#ffff"
                        android:textSize="17dp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/textView17"
                            android:layout_width="40dp"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text="0"
                            android:textColor="#FF0000"
                            android:textSize="20dp"
                            android:textStyle="bold" />

                        <TextView
                            android:id="@+id/textView18"
                            android:layout_width="20dp"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text="-"
                            android:textColor="#ffff"
                            android:textSize="20dp"
                            android:textStyle="bold" />

                        <TextView
                            android:id="@+id/textView19"
                            android:layout_width="40dp"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text="0"
                            android:textColor="#ffff"
                            android:textSize="20dp"
                            android:textStyle="bold" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:orientation="horizontal">

                    </LinearLayout>
                </LinearLayout>


            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginLeft="0dp"
                android:orientation="vertical"
                >

                <TextView
                    android:id="@+id/TextViewID"
                    android:layout_width="110dp"
                    android:layout_height="110dp"
                    android:layout_marginTop="80dp"
                    android:layout_marginLeft="35dp"
                    android:background="@drawable/green_circle"
                    android:gravity="center"
                    android:text="2"
                    android:textColor="#ff2800"
                    android:textSize="13sp" />
            </LinearLayout>


        </LinearLayout>


    </LinearLayout>
</ScrollView>

  </RelativeLayout>

What im getting on the screen:

在此处输入图像描述

ive tried using different devices with different screen sizes but all give the same result. How can i solve this. TIA..!!!

I think it's because the LinearLayout where that round TextView is, is actually a child of another LinearLayout with horizontal orientation, and you have another empty LinearLayout of width 250dp right before it, which pushes the relevant layout out of screen. Can you try removing the empty LinearLayout and see if it helps?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM