有没有人制作过一个视图,它接受文本、图像并让文本环绕图像?
我的意思是类似于此处所提出的问题。我看到人们建议使用静态布局,但我不明白这是如何解决的。我也看到有人建议使用网络视图,但这似乎很愚蠢。我想要一个可以接受 XML 输入的可重用视图,并且我应该能够在 ListView 中使用它,而无需在每行中创建 web 视图。有想法吗?
我已经通过自己绘制所有内容来这个工作,但我陷入了单词破坏问题。
我还希望图像是可点击的,我已经有了,但具有与我们都习惯的 statelistdrawables 相同的功能。我是否必须维护视图中的图像状态并根据该状态更改要绘制的可绘制对象?
I mean something like what's asked here. I see people are suggesting using a staticlayout, but I don't understand how that solves it. I've also seen people suggesting webviews, but that seems stupid. I want a reusable View that can take XML input, and I should be able to use it in a ListView without making a webview inside each row. Ideas?
I've got this working by drawing everything myself, but I'm stuck at the words breaking issue.
I'd also like the image to be clickable, which I've kinda got already, but with the same functionality of the statelistdrawables we're all used to. Do I have to maintain image state in the view and change which drawable to draw based on that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许可以使用 WebView 尝试这个答案。
编辑:在使用 getLineCount()、getLineLastVisible() 和各种省略号设置之后,我得出的结论是,这并不是本意。
理论上,您可以使用 getLineCount() 和 getLineLastVisible() 来测量适合视图的文本并适当地填充第二个溢出视图。不幸的是,这些实际上与 TextView 的可见(屏幕上)部分没有任何关系,并且如果有隐藏的行,则只能显示 3 行的 TextView 会很乐意在 getLineCount() 中报告更多行。
我认为这个问题的一般解决方案需要将 TextView.java 的各个部分拼凑成您自己的 ViewGroup(它将包含插入图像或要布局的视图)。
简短的回答:鉴于当前的框架,这并不容易做到。
Perhaps try this answer, using a WebView.
Edit: after playing with getLineCount(), getLineLastVisible(), and various ellipsis settings, I've come to the conclusion that this was not meant to be.
In theory you could use getLineCount() and getLineLastVisible() to measure the text that fit in the view and populate a second overflow view appropriately. Unfortunately these don't actually have anything to do with the visible (on screen) portion of the TextView, and a TextView that is only able to show 3 lines will happily report many more lines in getLineCount() if there are lines hidden.
I think a general solution to this problem is going to require hacking together your own ViewGroup (it would contain an inset image or the View to layout around) from pieces of TextView.java.
Short answer: This is not easy to do given the current framework.