often9 2022-06-15 19:15 采纳率: 50%
浏览 53
已结题

悬浮球之子项按钮左右弹出问题

我现在想做一个可以移动的按钮,在安卓手机左边的时候,子选项按钮向右展开,靠右边,向左展开,我目前实现的方法是,把按钮的左右子选项边全部做出,再进行实现左右弹出,但是现在在靠右边的时候,发现左边按钮它无法全部显示,仔细查阅,发觉是由于按钮布局界面,一开始,把左边按钮移开至屏幕外
按钮.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:clipChildren="false"
    tools:parentTag="android.widget.LinearLayout">

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="-65dp"
        android:clipChildren="false">

        <LinearLayout
            android:id="@+id/Rv2"
            android:layout_width="88dp"
            android:layout_height="50dp"
            android:layout_marginLeft="0dp"
            android:background="@drawable/tanku_2"
            android:visibility="gone"
            tools:visibility="visible">

            <ImageView
                android:id="@+id/Rv3"
                android:layout_width="73dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:background="@drawable/sh1" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/v2"
            android:layout_width="88dp"
            android:layout_height="50dp"
            android:layout_marginLeft="90dp"
            android:background="@drawable/tanku1"
            android:visibility="gone"
            tools:visibility="visible">

            <ImageView
                android:id="@+id/v3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="20dp"
                android:background="@drawable/sh1" />

        </LinearLayout>

        <ImageView
            android:id="@+id/v1"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginLeft="65dp"
            android:background="#00000000"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />
    </FrameLayout>
</merge>

运行结果及报错内容

整体布局图片如下图所示:

img


我现在的布局图片

img

我的解答思路和尝试过的方法

我有想过,如果一开始就不把图片超过屏幕进行布局,也是可以实现的,但是问题是,如果这样布局,即使我一开始隐藏了右边按钮
它悬浮按钮图标距左边每次都会有边距

我想要达到的结果

移动悬浮球之后不出现靠左边有边距,悬浮球在右边的时候左边按钮正常正常展示弹出

  • 写回答

4条回答

  • 邹奇 博客专家认证 2022-06-20 10:26
    关注

    换个思路,采用popupwindow来实现,就不用关心左右布局了,只需要关注什么时候将popupwindow显示在悬浮球的左或右了。popupwindow显示可以动态设置宽高,显示在屏幕的哪个位置,很方便的

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 6月30日
  • 已采纳回答 6月22日
  • 创建了问题 6月15日

悬赏问题

  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)