简体   繁体   English

所有屏幕分辨率下图像上按钮的位置相同

[英]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.

相关问题 Android Canvas-在所有屏幕分辨率下将drawText放置在相同位置的文本 - Android Canvas - Position text with drawText in the same location on all screen resolutions 所有Android设备上的UI元素(按钮,图像按钮)的位置相同 - Same position for UI elements (buttons, image buttons) on all android devices Android按钮,所有等高高度都填充到屏幕底部,所有分辨率 - Android buttons, all equal height to fill to bottom of the screen, all resolutions 如何获得android中所有分辨率的图像的相同坐标? - How to get same co-ordinates for image for all resolutions in android? Android:具有不同分辨率的屏幕中按钮的位置 - Android: position of buttons in screens with different resolutions 带按钮的表格布局-第一个按钮(1x1)的背景大小在屏幕上看起来与其他按钮不同(所有图像均使用相同的图像) - Table layout with buttons - Background size of 1st button(1x1) is appearing different in screen than other buttons (using same image for all) Android:按钮屏幕网格的宽度不会随着不同的屏幕分辨率而改变 - Android: Width of a grid of buttons screen does not change with different screen resolutions android屏幕以相同的密度支持不同的分辨率 - android screen supporting for different resolutions in same density 在屏幕的 % 中放置文本区域和按钮 - Position textareas and buttons in % of the screen Android Image定位可支持多种屏幕分辨率 - Android Image positioning to support multiple screen resolutions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM