ANDROID:如何固定 ImageButton 相对于背景的位置?

发布于 2024-10-02 14:16:03 字数 711 浏览 0 评论 0原文

如何固定 ImageButton/Button/ImageView 相对于背景的位置/布局?

我尝试过这样的操作:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_img"
>

<ImageButton
    android:id="@+id/btn1"
    android:layout_width="52dip"
    android:layout_height="52dip"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="87dip"        
    android:background="@drawable/btn1"
/>    
</RelativeLayout> 

当我更改显示分辨率时,background_img 会拉伸以覆盖新区域,但 ImageButton 不会按比例缩放并且不会按比例尊重底部边距。

How to fix the position/layout of a ImageButton/Button/ImageView relative to the background?

I'd tried something like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_img"
>

<ImageButton
    android:id="@+id/btn1"
    android:layout_width="52dip"
    android:layout_height="52dip"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="87dip"        
    android:background="@drawable/btn1"
/>    
</RelativeLayout> 

When I change the display resolution, the background_img stretch to cover the new area, but the ImageButton doesn't streetch and doesn't respect the bottom margin proportionately.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往昔成烟 2024-10-09 14:16:03

这是因为您对高度和高度进行了硬编码。将它们设置为 fill_parent,然后它将适合边距。

It's because you hardcoded the height and with. Set them to fill_parent and it will then fit the margin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文