简体   繁体   中英

Android studio TextViews disappear with android_below

I have written an XML script to align Textviews underneath each other, I have used android:Layout_below for the first few Textviews and they align under each other but when I add it to other Textviews to go under the Textview above it they disappear off screen. here is my 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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorWhite"
    android:orientation="vertical"
    android:scaleX="1"
    android:scaleY="1">

    <!--This xml page shows the user their sensor value information-->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/imageview_account_profile"
            android:layout_width="125dp"
            android:layout_height="125dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/profile"
            app:civ_border_color="#FFFFFF"
            app:civ_border_width="2dp" />

    </RelativeLayout>

    <TextView
        android:id="@+id/accountName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="137dp"
        android:text="TextView"
        android:visibility="visible" />

    <TextView
        android:id="@+id/kills"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="40dp"
        android:layout_marginTop="166dp"
        android:text="kills: "
        android:textSize="25sp" />

    <TextView
        android:id="@+id/bulletsFired"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/kills"
        android:layout_alignEnd="@+id/kills"
        android:layout_marginTop="7dp"
        android:layout_marginEnd="-58dp"
        android:singleLine="true"
        android:text="bullets fired:"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/bulletsHit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/bulletsFired"
        android:layout_alignStart="@+id/bulletsFired"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="11dp"
        android:layout_marginBottom="227dp"
        android:text="bullets hit:"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/bulletsMissed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/kills"
        android:layout_alignParentBottom="true"
        android:layout_marginEnd="-80dp"

        android:layout_marginBottom="186dp"
        android:text="bullets missed:"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/score"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/kills"
        android:layout_alignParentBottom="true"
        android:layout_marginEnd="-18dp"

        android:layout_marginBottom="144dp"
        android:text="Score:"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/hitAccuracy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="14dp"
        android:layout_marginBottom="105dp"
        android:text="shot accuracy:"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/kills"
        android:layout_alignParentBottom="true"
        android:layout_marginEnd="-80dp"
        android:layout_marginBottom="64dp"
        android:text="Score per min:"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/timePlayed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/score"
        android:layout_alignParentBottom="true"
        android:layout_marginEnd="-44dp"
        android:layout_marginBottom="21dp"
        android:text="Time played:"
        android:textSize="25sp" />


</RelativeLayout>

so when I go to add an android:layout_below tag to bulletsHit TextView it disappears. Same goes for all of the Textviews after it if i try to add it to them.

Remove this attribute from all the views starting from bulletsHit and below:

android:layout_alignParentBottom="true"

and then add to all

android:layout_below=.....

Also remove any:

android:layout_marginBottom=....

Check this:

<!--This xml page shows the user their sensor value information-->
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/imageview_account_profile"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/profile"
        app:civ_border_color="#FFFFFF"
        app:civ_border_width="2dp" />

    </RelativeLayout>

    <TextView
        android:id="@+id/accountName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="137dp"
        android:text="TextView"
        android:visibility="visible" />

    <TextView
        android:id="@+id/kills"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="40dp"
        android:layout_marginTop="166dp"
        android:text="kills: "
        android:textSize="25sp" />

    <TextView
        android:id="@+id/bulletsFired"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/kills"
        android:layout_alignEnd="@+id/kills"
        android:layout_marginTop="7dp"
        android:layout_marginEnd="-58dp"
        android:singleLine="true"
        android:text="bullets fired:"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/bulletsHit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/bulletsFired"
        android:layout_alignStart="@+id/bulletsFired"
        android:layout_marginStart="11dp"
        android:text="bullets hit:"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/bulletsMissed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/kills"
        android:layout_below="@+id/bulletsHit"
        android:layout_marginEnd="-80dp"
        android:text="bullets missed:"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/score"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/kills"
        android:layout_below="@+id/bulletsMissed"
        android:layout_marginEnd="-18dp"
        android:text="Score:"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/hitAccuracy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_marginStart="14dp"
        android:layout_below="@+id/score"
        android:text="shot accuracy:"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/kills"
        android:layout_marginEnd="-80dp"
        android:layout_below="@+id/hitAccuracy"
        android:text="Score per min:"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/timePlayed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/score"
        android:layout_marginEnd="-44dp"
        android:layout_below="@+id/textView8"
        android:text="Time played:"
        android:textSize="25sp" />
</RelativeLayout>

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