我在画布上的椭圆路径周围绘制文本。在我的 Infinix 和三星 S9(API 28)设备上没有拉伸,但在这两个设备上没有相同的行为,例如 M 字母附加有不同的弧点但不拉伸。但在其他 Mi 和三星设备上,它会围绕弧线拉伸文本。我没有得到这个问题的原因。您可能会看到以下屏幕的屏幕截图。
图 1
图 2
图 3
图 4
布局:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/frame"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</FrameLayout>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="Testing Device"
android:id="@+id/t1"
android:layout_below="@id/frame"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="Samsung SM-N920C(Android 7.0 API 24)"
android:layout_below="@id/t1"/>
活动:
public class MainActivity extends AppCompatActivity {
ImageView mImageView;
Canvas canvas;
RectF oval;
Bitmap bitmap;
Path path;
Paint paint;
Paint paint_for_curve;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImageView = (ImageView)findViewById(R.id.iv);
path = new Path();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextSize(80);
paint.setColor(Color.BLACK);
paint.setUnderlineText(true);
if (paint.isUnderlineText()) {
Toast.makeText(this, "Underline Text", Toast.LENGTH_SHORT).show();
}
paint_for_curve = new Paint();
paint_for_curve.setColor(Color.RED);
bitmap = Bitmap.createBitmap(
(int)700, // Width
(int)700, // Height
Bitmap.Config.ARGB_8888); // Config
canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE);
oval = new RectF(265,265,400,400);
path.addArc(oval,180,359);
canvas.drawTextOnPath("Hello World",path,20,-10,paint);
canvas.drawPath(path,paint_for_curve);
mImageView.setImageBitmap(bitmap);
}
}
没有错误消息,我希望所有设备都具有相同的行为