[英]Same position of Buttons on Image with all screen resolutions
I'm trying to stick some ImageButtons on specific positions on ImageView. 我试图在ImageView的特定位置上粘贴一些ImageButton。 the problem is that i have to use absolute layout for the ImageButtons, and when I change the screen resolution all the ImageButtons moving from their places.
问题是我必须对ImageButton使用绝对布局,并且当我更改屏幕分辨率时,所有ImageButton均从其位置移动。
I've looking for an answer in all the web and just can't find anything. 我一直在网上寻找答案,却找不到任何东西。
Thank you. 谢谢。
I recommand you to not use absolute position in your layout. 我建议您不要在布局中使用绝对位置。 Use containers and some margins if you can to put your buttons at the right position.
如果可以将按钮放在正确的位置,请使用容器和一些边距。
If you really need absolute position depending on device, you can use specific dimensions for each kind of resolution. 如果您确实需要根据设备确定绝对位置,则可以为每种分辨率使用特定的尺寸。 See here:
看这里:
http://developer.android.com/training/basics/supporting-devices/screens.html http://developer.android.com/training/basics/supporting-devices/screens.html
Just use relative layout instead of absolute layout . 只需使用相对布局而不是绝对布局即可 。 if you dont like relative layout, you may use absolute layout, there is nothing wrong with it, its just not practical in most situations.
如果您不喜欢相对布局,则可以使用绝对布局,这没什么不对的,在大多数情况下它并不实际。 You may use absolute layout and scale the views on the screen with something like this: Scale a view and its layered subviews relatively
您可以使用绝对布局并按以下方式缩放屏幕上的视图:相对缩放视图及其分层的子视图
Dianne Hackborn (works at google) says : 黛安·哈克伯恩(谷歌作品)说 :
I'll say again: we are not going to remove AbsoluteLayout from a future release, but we strongly discourage people from using it.
我再说一遍:我们不会从将来的版本中删除AbsoluteLayout,但是我们强烈劝阻人们不要使用它。
If you choose to not believe me, you are welcome to, but I am not responsible for you making that decision.
如果您选择不相信我,欢迎您,但是我对您做出的决定不承担任何责任。
This is how to overlay buttons: 这是叠加按钮的方法:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/image" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="34dp"
android:layout_marginRight="40dp"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button2"
android:layout_below="@+id/button1"
android:layout_marginRight="37dp"
android:layout_marginTop="108dp"
android:text="Button" />
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.