How can I place an background image to a the left upper corner of TextView in android
Can you please tell me how can I place an background image to a the left upper corner of TextView in android? I would like the image not to be scaled by android.
I have tried
Resources res = getResources(); setCompoundDrawables(res.getDrawable(R.drawable.icon48x48_1), null, null, null);
Nothing is shown.
And I have tried set开发者_JAVA技巧Background(R.drawable.icon48x48_1);
But it stretches the image.
Thank you for any help.
Have you tried setting the DrawableLeft in you xml layout of the textview?
android:drawableLeft="@+id/img">
You could always make your new background image a 9-patch and put the stretchable areas on the right and bottom in a transparent area.
This is really a dirty hack so use it only as your last resource.
If this is what you want
you can do something like
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;
}
});
using a FrameLayout
containing both the ImageView
and TextView
.
Notice that if the icon spans more than one line it's not going to work.
精彩评论