vergil corleone
vergil corleone

Reputation: 1101

TextViews invisible inside LinearLayout?

I have some TextViews inside a LinearLayout. At runtime, the LinearLayout is visible, but none of the TextViews are. Here is the XML:

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5384615384615385"
        android:scaleType="fitXY"
        android:adjustViewBounds="true">
<LinearLayout 
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
    >
    <TextView
            android:id="@+id/onezero"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="one"
            android:typeface="sans"
            android:layout_weight="1"
            android:layout_margin="17dp"
            android:textIsSelectable="true"
            android:clickable="true" />
    <TextView
            android:id="@+id/oneone"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="two"
            android:typeface="sans"
            android:layout_margin="17dp"
            android:textIsSelectable="true"
            android:clickable="true" />
    <TextView
            android:id="@+id/onefour"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="three"
            android:layout_weight="1"
            android:typeface="sans"
            android:layout_margin="17dp"
            android:textIsSelectable="true"
            android:clickable="true" />
    <TextView
            android:id="@+id/other"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="four"
            android:layout_margin="17dp"
            android:typeface="sans"
            android:layout_weight="1" 
            android:textIsSelectable="true"
            android:clickable="true" />
    </LinearLayout>
    <ScrollView 
        android:id="@+id/scrollview1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:fillViewport="true">
    <TextView
            android:id="@+id/tv1"
            android:layout_width="fill_parent"
        android:layout_height="wrap_content"

            android:typeface="sans"
            android:textSize="17sp" 
            />

    </ScrollView>
    </LinearLayout>
</FrameLayout>

How do I make them visible?

EDIT: Code that accesses this layout:

void fragment(){
                ten.setTextColor(0xFFFFFF);//These are the 4 TextViews
        eleven.setTextColor(0xFFFFFF);
        fourteen.setTextColor(0xFFFFFF);
        other.setTextColor(0xFFFFFF);

            ten.setVisibility(View.VISIBLE);
            eleven.setVisibility(View.VISIBLE);
        fourteen.setVisibility(View.VISIBLE);
        other.setVisibility(View.VISIBLE);
}

Code where I am initializing the textviews:

ten=(TextView)findViewById(R.id.onezero);
eleven=(TextView)findViewById(R.id.oneone); 
fourteen=(TextView)findViewById(R.id.onefour);
other=(TextView)findViewById(R.id.other);

EDIT: I tried clicking on the LinearLayout area and the TextViews are registering clicks.. that means that they are there but invisible...

Upvotes: 0

Views: 1567

Answers (6)

vergil corleone
vergil corleone

Reputation: 1101

Apparently, using hex codes for colors in:

    ten.setTextColor(0xFFFFFF);//These are the 4 TextViews
    eleven.setTextColor(0xFFFFFF);
    fourteen.setTextColor(0xFFFFFF);
    other.setTextColor(0xFFFFFF);

doesn't work. I switched the 0xFFFFFF with Color.WHITE:

    ten.setTextColor(Color.WHITE);//These are the 4 TextViews
    eleven.setTextColor(Color.WHITE);
    fourteen.setTextColor(Color.WHITE);
    other.setTextColor(Color.WHITE);

This works perfectly.

EDIT: Figured out why the hex codes didn't work. We need to attach a transparency hex at the beginning of every hex. For example if you want the colors to be 80% opaque, here's how to find the transparency hex:

255 * 0.8 = 204

Now convert 204 to hex( using google), you'll get 0xCC. Add this before the hex code, and you'll get 0xCCFFFFFF. Using this makes it work perfectly.

Upvotes: 0

amalBit
amalBit

Reputation: 12181

The color you are applying is white...

 0xFFFFFF

try changing the color to contrast with your layout color..

Edit:

Its took a long time for me to realize this.. try it with the following code:

 textview.setTextColor(Color.parseColor("#bdbdbd"));

Upvotes: 2

Sonu Singh Bhati
Sonu Singh Bhati

Reputation: 1073

You have not assigned the layout_height of your parent layout i.e. FrameLayout. Try this:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5384615384615385"
    android:adjustViewBounds="true"
    android:scaleType="fitXY" >

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

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/onezero"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="17dp"
                android:layout_weight="1"
                android:clickable="true"
                android:text="one"
                android:textIsSelectable="true"
                android:typeface="sans" />

            <TextView
                android:id="@+id/oneone"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="17dp"
                android:layout_weight="1"
                android:clickable="true"
                android:text="two"
                android:textIsSelectable="true"
                android:typeface="sans" />

            <TextView
                android:id="@+id/onefour"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="17dp"
                android:layout_weight="1"
                android:clickable="true"
                android:text="three"
                android:textIsSelectable="true"
                android:typeface="sans" />

            <TextView
                android:id="@+id/other"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="17dp"
                android:layout_weight="1"
                android:clickable="true"
                android:text="four"
                android:textIsSelectable="true"
                android:typeface="sans" />
        </LinearLayout>

        <ScrollView
            android:id="@+id/scrollview1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true"
            android:scrollbars="vertical" >

            <TextView
                android:id="@+id/tv1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:typeface="sans" />
        </ScrollView>
    </LinearLayout>

</FrameLayout>

Upvotes: 0

RajaReddy PolamReddy
RajaReddy PolamReddy

Reputation: 22493

Change your layout with this prefixes

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

or

In FrameLayout android:layout_height="0dp" this will make the view invisible, probably intended for layout_width should be wrap_content

Upvotes: 0

R9J
R9J

Reputation: 6715

Add this in your xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

And then change your text color in java class

use

000000

instead

0xFFFFFF

Upvotes: 0

smuk
smuk

Reputation: 351

you are using android:layout_weight - ratio based space distribution. To make it work you have to set:

android:layout_width="0dp"

Upvotes: 0

Related Questions