简体   繁体   中英

TextView is not showing in layout

i've issue with the TextView in XML. this is my XML code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    tools:context=".frontScreen">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorAccent"
        android:gravity="center"
        android:orientation="horizontal"
        android:padding="@dimen/activity_horizontal_margin">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/plan"
            android:shadowColor="@color/colorPrimary"
            android:textColor="@color/colorPrimary"
            android:textSize="30sp"
            android:shadowRadius="2"
            android:gravity="center_horizontal"

            android:shadowDx="1"
            android:shadowDy="1"
           />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/colorAccent"
        android:gravity="center"
        android:orientation="horizontal"
        android:padding="@dimen/activity_horizontal_margin">

        <Button
            android:id="@+id/plan1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle" />

        <Button
            android:id="@+id/plan2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle" />


</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

if i write TextView is linear layout. then it overlapped with buttons. so i use 2 layouts relative and linear. when i click the TextView in design it looks like that TextView has exact space that i want but Text is disappeared

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    tools:context=".frontScreen">




    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/colorAccent"
        android:gravity="center"
        android:orientation="horizontal"
        android:padding="@dimen/activity_horizontal_margin">

        <Button
            android:id="@+id/plan1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle" />

        <Button
            android:id="@+id/plan2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle" />


    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorAccent"
        android:gravity="center"
        android:orientation="horizontal"
        android:padding="@dimen/activity_horizontal_margin">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="plan"
            android:shadowColor="@color/colorPrimary"
            android:textColor="@color/colorPrimary"
            android:textSize="30sp"
            android:shadowRadius="2"
            android:gravity="center_horizontal"

            android:shadowDx="1"
            android:shadowDy="1"
            />
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

hope this helps. But for better working you need to take relativelayout and linearlayout in single layout. feel free to ask if this doesn't works

EDIT:

If you need this in a single view you can try

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorAccent"
        android:orientation="horizontal"
        android:padding="@dimen/activity_horizontal_margin">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="plan"
            android:shadowColor="@color/colorPrimary"
            android:textColor="@color/colorPrimary"
            android:textSize="30sp"
            android:shadowRadius="2"
            android:layout_alignParentTop="true"
            android:gravity="center_horizontal"
            android:shadowDx="1"
            android:shadowDy="1" />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/colorAccent"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_centerInParent="true"
        android:padding="@dimen/activity_horizontal_margin">

        <Button
            android:id="@+id/plan1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle" />

        <Button
            android:id="@+id/plan2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle" />

    </LinearLayout>

    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

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