3

I have two TextViews in a linear layout. The first Textview, call it pen_name, has an accompanying image; the second TextView is just text. On the Graphical Layout, everything shows up fine. But when I run the app on a real device, the image but not the text of the first TextView shows. The second TextView works fine. Here is the code.

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

        <TextView
            android:id="@+id/pen_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:drawableLeft="@drawable/a_pen"
            android:drawablePadding="3dp"
            android:gravity="center_vertical"
            android:text="my_pseudonym"
            android:textColor="#1083f0"
            android:textSize="12sp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="2dp"
            android:gravity="center_vertical"
            android:text="Writer"
            android:textColor="#1083f0"
            android:textSize="12sp" />
    </LinearLayout>
Cote Mounyo
  • 13,817
  • 23
  • 66
  • 87
  • 5
    @Balavishnu you don't sound like you know much android. Why would he use an ImageView when a TextView can handle both text and image? – Pouton Gerald Jul 27 '13 at 09:36
  • Use spannable interface to solve your problem, [refer here](http://blog.stylingandroid.com/archives/177) – CRUSADER Jul 27 '13 at 09:38
  • You should define bounds of our textView. http://stackoverflow.com/questions/6859525/drawable-shape-not-showing-when-used-in-combination-with-androiddrawablebottom/6865765#6865765 http://stackoverflow.com/questions/8318765/how-do-i-use-a-compound-drawable-instead-of-a-linearlayout-that-contains-an-imag?rq=1 – Mohamad Ghafourian Jul 27 '13 at 09:38
  • :) Old school, need to be updated... Haven't used TextView for a while! – Niko Jul 27 '13 at 09:42
  • What is your device? besides use @string resource and try. – Niko Jul 27 '13 at 09:47
  • @CRUSADER spannable trick didn't work. – Cote Mounyo Jul 27 '13 at 09:50
  • @MohamadGhafourian I just finished reading your links. My drawable is not the problem. It is the text portion that is not showing. – Cote Mounyo Jul 27 '13 at 09:56
  • I am testing on both nexus 4 and S4. Same problem is happening. – Cote Mounyo Jul 27 '13 at 10:05

1 Answers1

0

I tested your code on my Galaxy S3, working perfectly, I can see the text.

The size of the drawable on your screen depends on the size of the image in the original file when using compound drawables with textviews, it means you can't really control the size of the drawable and if it's too wide, it might just cover up the text.

You could try with a smaller image or by providing a smaller image for smaller screen sizes.

2Dee
  • 8,609
  • 7
  • 42
  • 53