2013-07-27 31 views
3

我有两个线性布局的TextView。第一个Textview叫做pen_name,有一个伴随的图像;第二个TextView就是文本。在图形布局上,一切都显示正常。但是,当我在真实设备上运行应用程序时,图像而不是第一个TextView的文本显示。第二个TextView工作正常。这是代码。LinearLayout中的TextView不显示文本部分,但显示图像很好

<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> 
+5

@Balavishnu你不会听起来像你知道很多的机器人。当TextView可以处理文本和图像时,为什么他会使用ImageView? –

+0

使用spannable接口来解决你的问题,[请参考这里](http://blog.stylingandroid.com/archives/177) – CRUSADER

+0

你应该定义我们的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-c​​ontains-an-imag?rq = 1 –

回答

0

我测试了你的代码在我的Galaxy S3上,工作完美,我可以看到文本。

当你在屏幕上使用复合drawable时,屏幕上的drawable的大小取决于原始文件中图像的大小,这意味着你不能真正控制drawable的大小,如果它太宽,可能只是掩盖了文字。

您可以尝试使用较小的图像或通过为较小的屏幕尺寸提供较小的图像。

相关问题