我正在寻找一种在 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];
我希望有人能帮助我完成这项任务。提前致谢!
最佳答案
查看此库以获取流畅的文本: https://github.com/deano2390/FlowTextView
关于android - 自定义形状的 TextView ,Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29632499/