Singular1ty
Singular1ty

Reputation: 2615

TextView Not Showing Text

I'm something of an Android noob, and for the life of me, I can't work out why my TextView isn't showing.

Here's my Layout.

<RelativeLayout 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:orientation="vertical" 
tools:context="com.petastapleton.tapintoabetteryou.MainActivity" 
android:background="@color/light_gray">

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="3" 
    >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginBottom="10dp"
        android:layout_weight="1"
        android:background="@color/accent_blue" >

        <TextView
            android:id="@+id/row1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"                    
            android:layout_span="2"
            android:textColor="@color/White"
            android:textSize="12sp"
            android:text="Hello"
         />     
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_weight="1"
        android:layout_marginBottom="10dp"
        android:background="@color/mid_gray">
        <TextView
            android:id="@+id/row2"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"                    
            android:layout_span="2"
         />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_weight="1"
        android:background="@color/accent_blue">
        <TextView
            android:id="@+id/row3"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"                    
            android:layout_span="2"
         />
    </TableRow>

</TableLayout>

</RelativeLayout>

Ideally, I should have some white words in the top-row of my table - instead, the row expands slightly, indicating something happened there, but there's no words.

Screenshot below (from Eclipse, but even emulated with AVD it doesn't change anything)

Screenshot of my app

Upvotes: 0

Views: 1899

Answers (4)

Pradeep Sheoran
Pradeep Sheoran

Reputation: 493

You mention WeightSum but you dont mention WeightSum in layout. Which weight you want to divide in another weight sum. In parent layout give the WeightSum then add weight sum and then give the weight to all text and made height 0dp.

You want to make it Genric layout so put weightSum in Parent layout that break the screen in 2-2inch of partition and then put weight to all UI widget and in UI widget height made 0dp.

In Table Gives Weight Sum and complete the Weight in UI of child of Table WeightSum.


This was about layout but you text not show after this then set Margin or Alignment because your text is going out side of the screen.

Upvotes: 0

Nibha Jain
Nibha Jain

Reputation: 8141

Replace this

 <TextView
            android:id="@+id/row1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"                    
            android:layout_span="2"
            android:textColor="#ffffff"
            android:textSize="12sp"
            android:text="Hello"
         /> 

to

 <TextView
            android:id="@+id/row1"


            android:textColor="#ffffff"
            android:textSize="12sp"
            android:text="Hello"
         />  

Upvotes: 0

Aman Singh
Aman Singh

Reputation: 360

Try this:

    <TextView
                android:id="@+id/row1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/White"
                android:textSize="12sp"
                android:text="Hello"/>

Upvotes: 1

Exceptional
Exceptional

Reputation: 3004

Give orientation as

 android:orientation="horizontal"

in <TableRow>

android:layout_height="wrap_content" instead 0dp

Remove android:layout_span="2"

Upvotes: 1

Related Questions