如何将视图放置在确定的像素/位置
我需要在界面的自定义点放置一个视图(例如图像)。 有没有一种方法可以将视图放置在屏幕的精确像素/虚拟像素(dp)区域中?
我需要该视图显示在其他视图之上。
我认为必须放置一个RelativeLayout并在其中放置应用程序的所有布局,然后将视图相对于该布局放置,但我需要一种对未来开发人员更透明的方法才能使用它
编辑:
我忘了说我需要以编程方式并在运行时放置视图。我创建界面,在我的应用程序中制作内容,然后将图像放置在其他视图之上的视图的具体区域中,例如屏幕的一半、顶部或屏幕的 20% 或......
I need to put a view (a image for example) in a custom point of the interface.
Are there a method to put a view in a exact pixel / virtual pixel (dp) - zone of the screen?
I need that the view is displayed above the other views.
I think to obligatory put a RelativeLayout and inside it all the layouts of the app and then put the view relative to this layout but i need a method more transparent to the future developers be able use it
EDIT:
I forget to say that i need to put the view programmatically and in the run time. I create the interface, make things in my app and then put a image in a concrete zone of the view above the others views for example in the half of the screen or in the top or in the 20% of the screen or ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以设置布局的边距和其中视图的填充,并且可以指定相对于边缘或其他视图的位置。您还可以通过将(match_parent / fill_parent或wrap_content)替换为实际大小来指定布局的固定位置(请注意,您应该以dp或dip指定所有尺寸)
例如,您有一个线性布局,并且希望图像视图距左边距右侧 20 dp,您可以尝试如下操作:
如果您希望视图位于屏幕的某个部分,例如屏幕的顶部屏幕/屏幕底部等,您可以将它们全部嵌套在RelativeLayout中。这是一个很好的方法,它会消除任何混乱。
祝你好运,
阿克德
You can set margins for layouts and padding for views inside them, and you can specify position relative to edges, or to other views, there. Also you can specify fixed position for layouts by replacing (match_parent/fill_parent or wrap_content) with actual size( Note that you should specify all dimensions in dp or dip)
For instance you have a linear layout and you want an image view to be 20 dp to the right of the left margin you can try something like this:
If you want your views to be on a certain part of the screen, like top of the screen/ bottom of the screen etc, you can nest all of them inside a RelativeLayout. This is a nice way to do it, and it will remove any confusion.
Good luck,
Arkde
怎么样 FrameLayout 就像我发布的示例这里?
What about a FrameLayout as in the example I posted here?
您可以使用 AbsoluteLayout,尽管它已被弃用。
You can use AbsoluteLayout, although it's deprecated.