android - 自定义形状的 TextView ,Android

标签 android textview android-custom-view text-editor

我正在寻找一种在 Android 上制作自定义形状文本输入控件的方法,如屏幕截图所示。

需要的是有一些预定义的地方(灰色矩形)不会被文本覆盖。因此,当用户键入时 - 文本将根据灰色矩形的位置从左侧或右侧进行一些偏移。

在 iOS 上很容易做到,只需几行代码就可以了。但我找不到在 Android 上执行此操作的方法。请注意,灰色矩形可能不是文本输入组件的一部分。在 iOS 上,我只是将两个 UIImageView 放在 UITextView 上,并设置 rects 以排除渲染文本:

CGFloat margin = 8;
CGRect firstPathRect = CGRectMake(0, 80, 160 + margin, 90 + margin);
CGRect secondPathRect = CGRectMake([UIScreen mainScreen].bounds.size.width - 160 - 2 * margin, 280, 160, 90 + margin);
UIBezierPath *path1 = [UIBezierPath bezierPathWithRect:firstPathRect];
UIBezierPath *path2 = [UIBezierPath bezierPathWithRect:secondPathRect];
self.textView.textContainer.exclusionPaths = @[path1, path2];

我希望有人能帮助我完成这项任务。提前致谢!

screenshot from iOS

最佳答案

查看此库以获取流畅的文本: https://github.com/deano2390/FlowTextView

关于android - 自定义形状的 TextView ,Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29632499/

相关文章:

android - GridView 在一行中绘制其元素

java - Android - 创建动态 TextView

java - 程序与 CountDownTimer 配合得很好,直到还剩 3 秒,然后它调用两次

android - ArrayList的高效onDraw

android - 使用 ionic 在屏幕上显示手机的地理位置

android - 如何围绕 ImageView 对齐 TextView?

android - 在 ListView android 中刷新自定义 View

android - 在Android中使用DownloadManager下载完成后通知栏消失

Android DatePicker 日期限制

Android:从JNI方法获取随机数