Is there any way to have UI elements slightly overlap (one on top of one another) without using absolute layouts?

给你一囗甜甜゛ 提交于 2019-12-01 19:00:03

问题


Lets say I have a list on screen, which I always want to be usable. I also want a small image or textview to slightly overlap the listview. Is anything this possible without using absolute layout parameters?

I've never seen it in any android app or tutorial, but there are things like this in many iPhone apps. It adds a nice touch.

(Also, I don't have any code to show because I'm not sure where to start)


回答1:


Relative Layouts also allow things to overlap. Views declared later in the xml will be on top. I believe that aligning view edges and use of margins should allow you to achieve this affect without great difficulty.




回答2:


You could use RelativeLayout and set for example android:layout_marginTop="-50dip" android:layout_below="@id/my_list".




回答3:


As well as RelativeLayouts, you can also use FrameLayouts to stack objects. Other than the z-order (last object declared = highest z-order), the child objects don't depend on the positioning of other objects in the group, so you can just set margins or gravity to position them.

So in your instance, just declare a TextView after your ListView, and position it wherever you want. It won't interfere with the ListView's positioning, and it will sit on top.



来源:https://stackoverflow.com/questions/5792496/is-there-any-way-to-have-ui-elements-slightly-overlap-one-on-top-of-one-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!