<?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>
整体布局图片如下图所示:
我有想过,如果一开始就不把图片超过屏幕进行布局,也是可以实现的,但是问题是,如果这样布局,即使我一开始隐藏了右边按钮
它悬浮按钮图标距左边每次都会有边距
移动悬浮球之后不出现靠左边有边距,悬浮球在右边的时候左边按钮正常正常展示弹出
换个思路,采用popupwindow来实现,就不用关心左右布局了,只需要关注什么时候将popupwindow显示在悬浮球的左或右了。popupwindow显示可以动态设置宽高,显示在屏幕的哪个位置,很方便的
有边距的可能是:
1、你的背景资源有边距
2、父布局有内边距
表示看的云里雾里不明白
是移动的时候只有中间那个圆圈,然后靠右就显示圆圈左边的内容,靠左就显示圆圈右边的内容?
这种为什么要用FrameLayout布局,看起来就好乱
用LinearLayout布局,移动的时候隐藏圆圈左右的View,靠边的时候再直接显示不就好了
屏幕外的其实就是Gone就好了,没必要显示
拖动结束之后调整悬浮View的偏移量到想要的位置。