赞
踩
牙叔教程 简单易懂
本篇教程是一个自定义控件的教学演示, 无任何实际功能,
更没有提现功能, 那只是一个自定义按钮
主要演示自动义控件和动画, 除此之外没有其他任何功能
再次强调, 本脚本只是UI演示, 无任何其他功能
主界面
popWindow
9.0.4
importClass(android.view.View); importClass(android.graphics.Color); importClass(android.graphics.drawable.GradientDrawable); importClass(android.text.Spannable); importClass(android.text.SpannableStringBuilder); importClass(android.text.style.ForegroundColorSpan); importClass(android.graphics.LinearGradient); importClass(android.graphics.Shader); importClass(android.graphics.Bitmap); importClass("android.graphics.BitmapFactory"); importClass(android.graphics.BitmapShader); importClass(android.view.WindowManager); importClass(android.widget.ArrayAdapter); importClass(android.widget.AdapterView); importClass(android.net.Uri); importClass(java.util.ArrayList); importClass(android.graphics.PaintFlagsDrawFilter); importClass(android.graphics.Color); importClass(android.animation.ObjectAnimator); importClass(android.animation.AnimatorListenerAdapter); importClass(android.util.TypedValue);
function getSpinnerAdapter(dataList) { let adapter = JavaAdapter(android.widget.SpinnerAdapter, { getCount: function () { return dataList.length; }, getItem: function (position) { return dataList[position]; }, getItemId: function (position) { return position; }, getViewTypeCount: function () { return 1; }, getItemViewType: function (pos) { return 0; }, getDropDownView: function (position, convertView, parent) { log("getDropDownView"); if (!convertView) { let boxXml = ( <frame> <TextView id="_text" gravity="center" textColor="#000000" textSize="20sp" /> </frame> ); convertView = ui.inflate(boxXml); } let item = dataList[position]; convertView.getChildAt(0).setText(item); return convertView; }, getView: function (position, convertView, parent) { log("getView"); if (!convertView) { let boxXml = ( <horizontal> <text id="name" paddingLeft="3" android:layout_width="wrap_content" android:layout_height="match_parent" textColor="#ffffff" gravity="center" textSize="10sp" ></text> <img tint="#ffffff" padding="-18 0 0 0" android:layout_width="30dp" android:layout_height="match_parent" android:layout_gravity="center_vertical" src="@drawable/ic_arrow_drop_down_black_48dp" ></img> </horizontal> ); convertView = ui.inflate(boxXml); } let item = dataList[position]; convertView.name.setText(item); return convertView; }, }); return adapter; }
function setOnTouchListener(floatyWindow, childView, clickAction) { childView.setOnTouchListener(function (view, event) { switch (event.getAction()) { case event.ACTION_DOWN: log("ACTION_DOWN"); x = event.getRawX(); y = event.getRawY(); windowX = floatyWindow.getX(); windowY = floatyWindow.getY(); downTime = new Date().getTime(); return true; case event.ACTION_MOVE: log("ACTION_MOVE"); //移动手指时调整悬浮窗位置 floatyWindow.setPosition(windowX + (event.getRawX() - x), windowY + (event.getRawY() - y)); return true; case event.ACTION_UP: log("ACTION_UP"); log("按下时长: " + (new Date().getTime() - downTime)); //如果判断为长按,退出脚本 if (new Date().getTime() - downTime > 3000 && event.getRawX() - x < 5 && event.getRawY() - y < 5) { exit(); } else { //手指弹起时如果偏移很小则判断为点击 if (Math.abs(event.getRawY() - y) < 5 && Math.abs(event.getRawX() - x) < 5) { clickAction(); } } return true; } return true; }); }
function getViewAttr(ballView) { let parentView = ballView.getParent(); let parentViewWidth = parentView.getWidth(); let parentViewHeight = parentView.getHeight(); let parentViewLeft = parentView.getLeft(); let parentViewRight = parentView.getRight(); let parentViewX = parentView.getX(); let parentViewY = parentView.getY(); let parentViewPaddingLeft = parentView.getPaddingLeft(); let parentViewPaddingRight = parentView.getPaddingRight(); let ballViewWidth = ballView.getWidth(); let ballViewHeight = ballView.getHeight(); let ballViewLeft = ballView.getLeft(); let ballViewRight = ballView.getRight(); let ballViewX = ballView.getX(); let ballViewY = ballView.getY(); let ball = { parentViewWidth: parentViewWidth, parentViewHeight: parentViewHeight, parentViewLeft: parentViewLeft, parentViewRight: parentViewRight, parentViewX: parentViewX, parentViewY: parentViewY, parentViewPaddingRight: parentViewPaddingRight, parentViewPaddingLeft: parentViewPaddingLeft, ballViewWidth: ballViewWidth, ballViewHeight: ballViewHeight, ballViewLeft: ballViewLeft, ballViewRight: ballViewRight, ballViewX: ballViewX, ballViewY: ballViewY, }; return ball; }
function setBackgroundRoundedRectangle(view) {
gradientDrawable = new GradientDrawable();
gradientDrawable.setShape(GradientDrawable.RECTANGLE);
gradientDrawable.setStroke(5, colors.parseColor(增量更新按钮颜色));
gradientDrawable.setCornerRadius(10);
gradientDrawable.setSize(50, 50);
view.setBackground(gradientDrawable);
}
mPopWindow.setOnDismissListener(
new PopupWindow.OnDismissListener({
onDismiss: function () {
backgroundAlpha(1);
},
})
);
部分内容来自网络
本教程仅用于学习, 禁止用于其他用途
747748653
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。