【问题标题】:Android - Put a button over an ImageView to the exact spotAndroid - 将一个按钮放在 ImageView 上的确切位置
【发布时间】:2015-09-22 13:23:34
【问题描述】:

我在这张图片上有一个ImageView(人体)和按钮。

是否有可能以某种方式轻松地在RelativeLayout 中为大多数不同的屏幕尺寸创建它?还是应该为不同的屏幕尺寸创建不同的布局?

您将如何进行?你有什么推荐的?

【问题讨论】:

  • 如果你的图片是全屏的,我只想说让它成为你的相对视图的背景,然后正常添加按钮

标签: android android-layout android-imageview android-button android-percentrelativelayout


【解决方案1】:

看看percent library。

它非常适合这样的事情,并且适用于所有设备。您必须计算出每个 PercentRelativeLayout 相对于您的人物图像的百分比宽度、高度和边距。

这是一个例子:

<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        app:layout_widthPercent="25%"
        android:layout_height="100dp"
        app:layout_marginLeftPercent="5%"
        android:background="#ff0000" />

</android.support.percent.PercentRelativeLayout>

记得要

compile 'com.android.support:percent:23.0.0'

【讨论】:

    【解决方案2】:

    这是一个带有可点击区域的图像视图示例。

    https://blahti.wordpress.com/2012/06/26/images-with-clickable-areas/

    希望对你有帮助。

    【讨论】:

    • 你有提示如何显示用户可以点击的按钮(或图像)(在可点击区域)?或者当用户点击可点击区域时改变图像的颜色?如果用户选择某个区域,它应该有不同的颜色(图像)。就像原始问题中的图片一样。
    • 使用自定义按钮或自定义切换按钮。在stackoverflow板上搜索,有很多条目在谈论这个。您可以使用库 ION 在 imageview 中加载 gif,有很多选项。选择一个试试看,如果不能继续,返回错误:)。
    【解决方案3】:

    是的,相对布局是可能的,但它很困难。

    为此你必须专注于

    1. 完美切割的不同图像。
    2. 将图像放入所有可绘制对象中。
    3. 创建相对布局并从一侧到另一侧的图像视图作为参考。
    4. 在不同的dimen.xml中添加边距

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多