Android 中的重叠视图?
我有一个线性布局,其中有一个文本框(多行,近 5 行)和图像视图。是否可以在textview上绘制图像(重叠)?
注意:我必须指定图像的坐标,该坐标不是静态的,可能位于文本上方的任何位置。
像这样的模型:
I have a linearlayout which have a textbox(multiline, nearly 5 lines) and image view. Is it possible to draw a image on textview(overlapping)?
Note: I have to specify the coordinates of the image, which are not static, and may be anywhere above text.
Something like this mockup:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为可以使用RelativeLayout来实现。
通过将 TextView 块放置在 ImageView 上方,可以确保图像视图与 TextView 重叠。现在,根据您的要求和位置,使用链接中的以下命令:-
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
您可以左右对齐、顶部和底部对齐。如果您使用对齐底部和其他内容,请使用负值来导航 ImageView。这将使其重叠。如果这有帮助,请告诉我
线性布局有什么具体原因吗?
I think it can be achieved using RelativeLayout.
By placing the TextView block above the ImageView, it ensures that the image view overlaps the TextView. Now, based on your requirements and position, use the following commands from the link :-
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
You can align left right, top and bottom. Use negative values to navigate the ImageView, if ur using align bottom and stuff.. This will make it to overlap. Please let me know if this was helpful
Is there any specific reason for Linear Layout?
您可以使用RelativeLayout轻松做到这一点。您可以让 ImageView 与 TextView 重叠,除非有特定原因使用 LinearLayout 。
You can do this easily using RelativeLayout . You can have an ImageView overlapping TextView Unless there is a specific reason for using LinearLayout .
如果您确实(确实)需要使用 LinearLayout,您可以继承 TextView 并覆盖 onDraw 绘制图像。
If you really (really) need to use LinearLayout, you can subclass TextView and override onDraw to draw your image.
在
所有xml文件
中,应该为其定义背景颜色,它将解决问题:将此
android:background="@android:color/black"
添加到您定义的视图标签。In
all your xml files
, should define the background color for it, it will solve the problem :Add this
android:background="@android:color/black"
in to the View tag you defined.