Reputation: 11829
I created a widget with text. I want to add ... to the end of the text where there is not enough place to show the whole text. I used android:ellipsize="end"
but only the first two rows are visible.
This is the widget layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="64dip"
android:layout_height="72dip"
android:layout_gravity="center"
android:id="@+id/widgetlayout">
<ImageView android:id="@+id/ImageView01"
android:layout_width="72dip"
android:layout_height="72dip"
android:scaleType="fitXY">
</ImageView>
<TextView
android:id="@+id/tvConfigInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="left"
android:textColor="#FFFFFF"
android:layout_margin="2dip"
android:ellipsize="end"
android:textSize="12dip" />
</RelativeLayout>
The first image is with the ellipsize effect. The second one is without it. You can see there is enough place to show more text.
I tried out in a 1x2 widget also, same happens
Thanks to Devunwired, I am now trying with this, but nothing has changed (I guess I am doing sg wrong)
RemoteViews views = new RemoteViews(c.getPackageName(), R.layout.widget_layout);
TextPaint paint = new TextPaint();
final float densityMultiplier = this.getResources().getDisplayMetrics().density;
final float scaledPx = 20 * densityMultiplier;
paint.setTextSize(scaledPx);
final float size = paint.measureText(widgettext);
Log.i("size", size + ""); //1716 e.g
while (widgettext != TextUtils.ellipsize(widgettext, paint, (float)GetDipsFromPixel(72), TextUtils.TruncateAt.END)) {
paint.setTextSize(paint.getTextSize() - 1);
}
views.setTextViewText(R.id.tvConfigInput, widgettext);
views.setTextColor(R.id.tvConfigInput, loadedtextcolor);
views.setFloat(R.id.tvConfigInput, "setTextSize", int_widgetfontsize);
Upvotes: 0
Views: 1055
Reputation: 63303
You've found one of my favorite framework bugs: http://code.google.com/p/android/issues/detail?id=2254
Feel free to star it and hope that we see a fix for this soon. The comments within also point to a number of solutions you can implement with a custom view to overcome the problem. You can also manually place the ellipsis using a combination of Paint.measureText()
and TextUtils.ellipsize()
HTH
Upvotes: 2