fix: 修改单击白色覆盖物不消失的问题
This commit is contained in:
parent
1dc23fdd3f
commit
bd3e498888
4
.idea/emulatorDisplays.xml
generated
4
.idea/emulatorDisplays.xml
generated
@ -10,7 +10,7 @@
|
||||
<list>
|
||||
<DisplayDescriptor>
|
||||
<option name="height" value="1920" />
|
||||
<option name="width" value="972" />
|
||||
<option name="width" value="1080" />
|
||||
</DisplayDescriptor>
|
||||
<DisplayDescriptor>
|
||||
<option name="displayId" value="6" />
|
||||
@ -23,7 +23,7 @@
|
||||
<PanelState>
|
||||
<option name="splitPanel">
|
||||
<SplitPanelState>
|
||||
<option name="proportion" value="0.7084547877311707" />
|
||||
<option name="proportion" value="0.7297297120094299" />
|
||||
<option name="firstComponent">
|
||||
<PanelState>
|
||||
<option name="displayId" value="0" />
|
||||
|
318
.idea/other.xml
generated
318
.idea/other.xml
generated
@ -1,318 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="direct_access_persist.xml">
|
||||
<option name="deviceSelectionList">
|
||||
<list>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="27" />
|
||||
<option name="brand" value="DOCOMO" />
|
||||
<option name="codename" value="F01L" />
|
||||
<option name="id" value="F01L" />
|
||||
<option name="manufacturer" value="FUJITSU" />
|
||||
<option name="name" value="F-01L" />
|
||||
<option name="screenDensity" value="360" />
|
||||
<option name="screenX" value="720" />
|
||||
<option name="screenY" value="1280" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="28" />
|
||||
<option name="brand" value="DOCOMO" />
|
||||
<option name="codename" value="SH-01L" />
|
||||
<option name="id" value="SH-01L" />
|
||||
<option name="manufacturer" value="SHARP" />
|
||||
<option name="name" value="AQUOS sense2 SH-01L" />
|
||||
<option name="screenDensity" value="480" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2160" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="31" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="a51" />
|
||||
<option name="id" value="a51" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy A51" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="akita" />
|
||||
<option name="id" value="akita" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 8a" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="b0q" />
|
||||
<option name="id" value="b0q" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy S22 Ultra" />
|
||||
<option name="screenDensity" value="600" />
|
||||
<option name="screenX" value="1440" />
|
||||
<option name="screenY" value="3088" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="32" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="bluejay" />
|
||||
<option name="id" value="bluejay" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 6a" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="caiman" />
|
||||
<option name="id" value="caiman" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 9 Pro" />
|
||||
<option name="screenDensity" value="360" />
|
||||
<option name="screenX" value="960" />
|
||||
<option name="screenY" value="2142" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="comet" />
|
||||
<option name="id" value="comet" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 9 Pro Fold" />
|
||||
<option name="screenDensity" value="390" />
|
||||
<option name="screenX" value="2076" />
|
||||
<option name="screenY" value="2152" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="29" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="crownqlteue" />
|
||||
<option name="id" value="crownqlteue" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy Note9" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="2220" />
|
||||
<option name="screenY" value="1080" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="dm3q" />
|
||||
<option name="id" value="dm3q" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy S23 Ultra" />
|
||||
<option name="screenDensity" value="600" />
|
||||
<option name="screenX" value="1440" />
|
||||
<option name="screenY" value="3088" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="e1q" />
|
||||
<option name="id" value="e1q" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy S24" />
|
||||
<option name="screenDensity" value="480" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2340" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="felix" />
|
||||
<option name="id" value="felix" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel Fold" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="2208" />
|
||||
<option name="screenY" value="1840" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="felix" />
|
||||
<option name="id" value="felix" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel Fold" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="2208" />
|
||||
<option name="screenY" value="1840" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="felix_camera" />
|
||||
<option name="id" value="felix_camera" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel Fold (Camera-enabled)" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="2208" />
|
||||
<option name="screenY" value="1840" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="gts8uwifi" />
|
||||
<option name="id" value="gts8uwifi" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy Tab S8 Ultra" />
|
||||
<option name="screenDensity" value="320" />
|
||||
<option name="screenX" value="1848" />
|
||||
<option name="screenY" value="2960" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="husky" />
|
||||
<option name="id" value="husky" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 8 Pro" />
|
||||
<option name="screenDensity" value="390" />
|
||||
<option name="screenX" value="1008" />
|
||||
<option name="screenY" value="2244" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="30" />
|
||||
<option name="brand" value="motorola" />
|
||||
<option name="codename" value="java" />
|
||||
<option name="id" value="java" />
|
||||
<option name="manufacturer" value="Motorola" />
|
||||
<option name="name" value="G20" />
|
||||
<option name="screenDensity" value="280" />
|
||||
<option name="screenX" value="720" />
|
||||
<option name="screenY" value="1600" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="komodo" />
|
||||
<option name="id" value="komodo" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 9 Pro XL" />
|
||||
<option name="screenDensity" value="360" />
|
||||
<option name="screenX" value="1008" />
|
||||
<option name="screenY" value="2244" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="lynx" />
|
||||
<option name="id" value="lynx" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 7a" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="31" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="oriole" />
|
||||
<option name="id" value="oriole" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 6" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="panther" />
|
||||
<option name="id" value="panther" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 7" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="q5q" />
|
||||
<option name="id" value="q5q" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy Z Fold5" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1812" />
|
||||
<option name="screenY" value="2176" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="30" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="r11" />
|
||||
<option name="id" value="r11" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel Watch" />
|
||||
<option name="screenDensity" value="320" />
|
||||
<option name="screenX" value="384" />
|
||||
<option name="screenY" value="384" />
|
||||
<option name="type" value="WEAR_OS" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="30" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="redfin" />
|
||||
<option name="id" value="redfin" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 5" />
|
||||
<option name="screenDensity" value="440" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2340" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="shiba" />
|
||||
<option name="id" value="shiba" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 8" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="tangorpro" />
|
||||
<option name="id" value="tangorpro" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel Tablet" />
|
||||
<option name="screenDensity" value="320" />
|
||||
<option name="screenX" value="1600" />
|
||||
<option name="screenY" value="2560" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="tokay" />
|
||||
<option name="id" value="tokay" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 9" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2424" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="29" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="x1q" />
|
||||
<option name="id" value="x1q" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy S20" />
|
||||
<option name="screenDensity" value="480" />
|
||||
<option name="screenX" value="1440" />
|
||||
<option name="screenY" value="3200" />
|
||||
</PersistentDeviceSelectionData>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -36,6 +36,7 @@ dependencies {
|
||||
|
||||
implementation libs.androidx.core.ktx
|
||||
implementation libs.androidx.appcompat
|
||||
implementation files('libs\\android.car.240829.jar')
|
||||
testImplementation libs.junit
|
||||
androidTestImplementation libs.androidx.junit
|
||||
androidTestImplementation libs.androidx.espresso.core
|
||||
|
BIN
automotive/libs/android.car.240829.jar
Normal file
BIN
automotive/libs/android.car.240829.jar
Normal file
Binary file not shown.
@ -18,6 +18,7 @@
|
||||
<activity
|
||||
android:name="com.mixiaoxiao.splitlayoutsample.SplitLayoutActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:screenOrientation="landscape"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
|
@ -67,10 +67,11 @@ public class SplitLayout extends ViewGroup {
|
||||
private Paint mPaint = new Paint();
|
||||
private int dragForgroundColor = Color.argb(0.88f, 1f, 1f, 1f); // 默认的前景色
|
||||
private int splitDragTouchCount = 2; // 默认拖动切换左右两个子View时的点击个数
|
||||
private boolean splitIsShowSnapshotView = false; // 拖动过程中是否显示快照图片
|
||||
private long mChildLongPressTime; // 记录用户长按拖动子View的初始时间
|
||||
private View switchLongPressChildView = null; // 记录用户长按拖动的子View
|
||||
private boolean hasSwitchChild = false; // 子View是否通过手势切换完成
|
||||
private long LONG_PRESS_TIME = 2000;
|
||||
private long LONG_PRESS_TIME = 1200;
|
||||
// private Vibrator vibrator;
|
||||
|
||||
public SplitLayout(Context context) {
|
||||
@ -112,6 +113,7 @@ public class SplitLayout extends ViewGroup {
|
||||
dragForgroundColor = a.getColor(R.styleable.SplitLayout_splitDragForgroundColor, dragForgroundColor);
|
||||
// 切换左右分割子View时手指的点击个数
|
||||
splitDragTouchCount = a.getInteger(R.styleable.SplitLayout_splitDragTouchCount, splitDragTouchCount);
|
||||
splitIsShowSnapshotView = a.getBoolean(R.styleable.SplitLayout_splitIsShowSnapshotView, splitIsShowSnapshotView);
|
||||
a.recycle();
|
||||
|
||||
mPaint.setColor(dragForgroundColor);
|
||||
@ -126,6 +128,12 @@ public class SplitLayout extends ViewGroup {
|
||||
checkChildren();
|
||||
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
// 重置子View的最小值
|
||||
if (mOrientation == VERTICAL) {
|
||||
mChildMinSize = heightSize/3;
|
||||
} else {
|
||||
mChildMinSize = widthSize/3;
|
||||
}
|
||||
if (widthSize > 0 && heightSize > 0) {
|
||||
mWidth = widthSize;
|
||||
mHeight = heightSize;
|
||||
@ -146,8 +154,12 @@ public class SplitLayout extends ViewGroup {
|
||||
}
|
||||
|
||||
// 初始化双缓冲对应的Bitmap和canvas
|
||||
cachedBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
|
||||
cachedCanvas = new Canvas(cachedBitmap);
|
||||
if (cachedBitmap == null) {
|
||||
cachedBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
if (cachedCanvas == null) {
|
||||
cachedCanvas = new Canvas(cachedBitmap);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("SplitLayout with or height must not be MeasureSpec.UNSPECIFIED");
|
||||
}
|
||||
@ -198,7 +210,7 @@ public class SplitLayout extends ViewGroup {
|
||||
}
|
||||
mHandleDrawable.setState(PRESSED_STATE_SET);
|
||||
mIsDragging = true;
|
||||
// getParent().requestDisallowInterceptTouchEvent(true);
|
||||
getParent().requestDisallowInterceptTouchEvent(true);
|
||||
getBitmapFromChildView(); // 截屏当前两个子View的图片,用于在拖动过程中的
|
||||
invalidate();
|
||||
} else {
|
||||
@ -224,7 +236,7 @@ public class SplitLayout extends ViewGroup {
|
||||
Log.d(TAG, "ACTION_MOVE");
|
||||
if (ev.getPointerCount() == 1) {
|
||||
if (mIsDragging) {
|
||||
// getParent().requestDisallowInterceptTouchEvent(true);
|
||||
getParent().requestDisallowInterceptTouchEvent(true);
|
||||
if (mOrientation == VERTICAL) {
|
||||
float deltaY = y - mLastMotionY;
|
||||
onlyUpdateSplitPosition(deltaY);
|
||||
@ -246,11 +258,12 @@ public class SplitLayout extends ViewGroup {
|
||||
// 判断所有手指是否都到了另外一个子View内
|
||||
View tmpView = (switchLongPressChildView == mChild0)? mChild1:mChild0;
|
||||
if (isEventAllInChildView(tmpView, ev)) {
|
||||
// 震动提示用户,已实现换位
|
||||
// 多个触控位置全部移动到另外的View中,并且此前状态不是已切换状态,开始切换快照图片
|
||||
if (!hasSwitchChild) {
|
||||
// 震动提示用户
|
||||
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
|
||||
hasSwitchChild = true;
|
||||
Toast.makeText(getContext(), "实现切换", Toast.LENGTH_SHORT).show();
|
||||
// Toast.makeText(getContext(), "实现切换", Toast.LENGTH_SHORT).show();
|
||||
postInvalidate();
|
||||
}
|
||||
} else {
|
||||
@ -258,7 +271,7 @@ public class SplitLayout extends ViewGroup {
|
||||
if (hasSwitchChild) {
|
||||
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
|
||||
hasSwitchChild = false;
|
||||
Toast.makeText(getContext(), "恢复状态", Toast.LENGTH_SHORT).show();
|
||||
// Toast.makeText(getContext(), "恢复状态", Toast.LENGTH_SHORT).show();
|
||||
postInvalidate();
|
||||
}
|
||||
}
|
||||
@ -270,6 +283,7 @@ public class SplitLayout extends ViewGroup {
|
||||
performHapticFeedback(HapticFeedbackConstants.DRAG_START);
|
||||
mIsSwitching = true;
|
||||
mIsSwitchStart = false;
|
||||
postInvalidate(); // 开始进入切换左右位置的状态
|
||||
} else { // 划出当前View,则重置长按初始时间为0,且初始点按的childView也置为null
|
||||
mChildLongPressTime = 0;
|
||||
switchLongPressChildView = null;
|
||||
@ -279,9 +293,7 @@ public class SplitLayout extends ViewGroup {
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
if (hasSwitchChild) {
|
||||
switchChildViewPosition();
|
||||
}
|
||||
switchChildViewPosition(hasSwitchChild);
|
||||
hasSwitchChild = false;
|
||||
mIsSwitching = false;
|
||||
mIsSwitchStart = false;
|
||||
@ -302,6 +314,7 @@ public class SplitLayout extends ViewGroup {
|
||||
mLastMotionX = x;
|
||||
mLastMotionY = y;
|
||||
mIsDragging = false;
|
||||
postInvalidate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -330,7 +343,7 @@ public class SplitLayout extends ViewGroup {
|
||||
if (mOrientation == VERTICAL) {
|
||||
return y >= (mSplitPosition - (mHandleSize*2)) && y <= (mSplitPosition + (mHandleSize*2));
|
||||
} else {
|
||||
return x >= (mSplitPosition - (mHandleSize*2)) && x <= (mSplitPosition + (mHandleSize*2));
|
||||
return x >= (mSplitPosition - (mHandleSize*20)) && x <= (mSplitPosition + (mHandleSize*20));
|
||||
}
|
||||
|
||||
}
|
||||
@ -373,12 +386,16 @@ public class SplitLayout extends ViewGroup {
|
||||
child0Rect.set(0, 0, (int) (mSplitPosition - mHandleSize / 2), getHeight());
|
||||
child1Rect.set((int) (mSplitPosition + mHandleSize / 2), 0, getWidth(), getHeight());
|
||||
}
|
||||
cachedCanvas.drawBitmap(cachedBitmapArray[0], null, child0Rect, null);
|
||||
if (splitIsShowSnapshotView) {
|
||||
cachedCanvas.drawBitmap(cachedBitmapArray[0], null, child0Rect, null);
|
||||
}
|
||||
cachedCanvas.drawRect(child0Rect, mPaint);
|
||||
// cachedCanvas.drawBitmap(((BitmapDrawable)getContext().getDrawable(R.drawable.icon_app)).getBitmap(),
|
||||
// child0Rect.centerX() - (getContext().getDrawable(R.drawable.icon_app).getBounds().width()/2),
|
||||
// child0Rect.centerY() - (getContext().getDrawable(R.drawable.icon_app).getBounds().height()/2), null);
|
||||
cachedCanvas.drawBitmap(cachedBitmapArray[1], null, child1Rect, null);
|
||||
if (splitIsShowSnapshotView) {
|
||||
cachedCanvas.drawBitmap(cachedBitmapArray[1], null, child1Rect, null);
|
||||
}
|
||||
cachedCanvas.drawRect(child1Rect, mPaint);
|
||||
// cachedCanvas.drawBitmap(((BitmapDrawable)getContext().getDrawable(R.drawable.icon_app)).getBitmap(),
|
||||
// child1Rect.centerX() - (getContext().getDrawable(R.drawable.icon_app).getBounds().width()/2),
|
||||
@ -502,14 +519,19 @@ public class SplitLayout extends ViewGroup {
|
||||
}
|
||||
|
||||
// 切换两个子View的位置
|
||||
public void switchChildViewPosition() {
|
||||
public void switchChildViewPosition(boolean isReverse) {
|
||||
checkChildren();
|
||||
removeAllViews();
|
||||
addView(mChild1);
|
||||
addView(mChild0);
|
||||
View tempView = mChild0;
|
||||
mChild0 = mChild1;
|
||||
mChild1 = tempView;
|
||||
if (isReverse) {
|
||||
addView(mChild1);
|
||||
addView(mChild0);
|
||||
View tempView = mChild0;
|
||||
mChild0 = mChild1;
|
||||
mChild1 = tempView;
|
||||
} else {
|
||||
addView(mChild0);
|
||||
addView(mChild1);
|
||||
}
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
@ -536,11 +558,22 @@ public class SplitLayout extends ViewGroup {
|
||||
child0Rect.set((int) (mSplitPosition + mHandleSize / 2), 0, getWidth(), getHeight());
|
||||
}
|
||||
}
|
||||
cachedCanvas.drawBitmap(cachedBitmapArray[0], null, child0Rect, null);
|
||||
cachedCanvas.drawBitmap(cachedBitmapArray[0], new Rect(0,0, cachedBitmapArray[0].getWidth(), cachedBitmapArray[0].getHeight()), child0Rect, mPaint);
|
||||
cachedCanvas.drawRect(child0Rect, mPaint);
|
||||
cachedCanvas.drawBitmap(cachedBitmapArray[1], null, child1Rect, null);
|
||||
cachedCanvas.drawBitmap(cachedBitmapArray[1], new Rect(0,0, cachedBitmapArray[1].getWidth(), cachedBitmapArray[1].getHeight()), child1Rect, mPaint);
|
||||
cachedCanvas.drawRect(child1Rect, mPaint);
|
||||
canvas.drawBitmap(cachedBitmap, 0, 0, null);
|
||||
canvas.drawBitmap(cachedBitmap, 0, 0, mPaint);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置子View的最小宽度
|
||||
* */
|
||||
public int getmChildMinSize() {
|
||||
return mChildMinSize;
|
||||
}
|
||||
|
||||
public void setmChildMinSize(int mChildMinSize) {
|
||||
this.mChildMinSize = mChildMinSize;
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,6 @@ public class SplitLayoutActivity extends Activity {
|
||||
// }
|
||||
|
||||
// 切换两个子View的显示位置
|
||||
mHorizontalSplitLayout.switchChildViewPosition();
|
||||
mHorizontalSplitLayout.switchChildViewPosition(true);
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@
|
||||
app:splitOrientation="horizontal">
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_child0"
|
||||
android:background="@color/material_yellow_500"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
@ -15,5 +15,7 @@
|
||||
<attr name="splitDragForgroundColor" format="color"/>
|
||||
<!-- 分割要素拖动切换左右时,点击个数的设置 -->
|
||||
<attr name="splitDragTouchCount" format="integer"/>
|
||||
<!-- 拖动中间滑块时,是否动态修改快照图片的宽高 -->
|
||||
<attr name="splitIsShowSnapshotView" format="boolean"/>
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user