2010-02-17 165 views
1

您可以告诉我如何将背景图像放置在android的TextView左上角?我希望图像不被android缩放。如何将背景图像放置在android的文本视图的左上角?

我试过

Resources res = getResources(); setCompoundDrawables(res.getDrawable(R.drawable.icon48x48_1),null,null,null);

什么都没有显示。

我试过 setBackground(R.drawable.icon48x48_1);

但它延伸了图像。

谢谢你的帮助。

回答

0

这实在是一个肮脏的黑客,所以只用它作为你的最后一个资源。

如果这是你想要

alt text

您可以使用FrameLayout同时包含ImageViewTextView这样做

final TextView tv = (TextView) findViewById(R.id.TextView01); 
    tv.setTransformationMethod(new TransformationMethod() { 
     private static final String INDENT = "  "; 

     @Override 
     public void onFocusChanged(View view, CharSequence sourceText, 
       boolean focused, int direction, Rect previouslyFocusedRect) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public CharSequence getTransformation(CharSequence source, View view) { 
      return INDENT + source; 
     } 
    }); 

什么。 请注意,如果图标跨越多行,则不起作用。

2

你有没有尝试过在你的xml布局的Textview中设置DrawableLeft?

android:drawableLeft="@+id/img"> 
+1

是的,但它轮胎在我的TextView垂直中心drawable。我想要它在左上角布局。 – hap497 2010-02-17 23:19:31

1

您可以随时让您的新背景图像为9贴片,并将可伸缩区域放在右侧和底部的透明区域。

相关问题