Android 中的动态可扩展 textView?
我希望设计一个动态可扩展的 texview,用户从 textview 的边缘滑动手指,视图就会扩展,在调整自身大小的同时,也会调整其上方视图的大小。
我想我可以使用 onTouchListener 和 switch/case 来获取触摸翻译,但调整大小部分是我不确定的地方。关于什么方法可以做到这一点有什么想法吗?
I am looking to design a dynamically expandable texview, in that the user slides his finger from the edge of the textview, and the view expands, and while resizing up itself, resizing down the view above it.
I figure I could use an onTouchListener, with a switch/case to pick up touch translation, but the resizing part is where I am unsure about. Any ideas on what methods would work for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你可以将类似的东西放在触摸监听器的 ACTION_MOVE 部分中。您可以通过从 onTouch() 中传递给您的 MotionEvent 中取出值来找到起点和当前点。如果您希望它仅在一个方向上调整大小,那么您只需担心 x 或 y 即可。如果您想在所有方向上调整大小,那么您必须获得 X 和 Y 的距离,然后使用您得出的值调用 setHeight 和 setWidth。
I would think you could put something like this inside the ACTION_MOVE portion of your touch listener. You can find start point and current point from taking the values out of the MotionEvent that get passed to you in onTouch(). If you want it to only re-size in one direction then you just have to worry about either x or y. If you want to resize in all directions then you'll have to get a distance for both X and Y and then call setHeight and setWidth with the values that you come up with.