使用自定义锁定来锁定和解锁设备,与Start应用程序相同,到目前为止我谷歌并得到了一些问题,但没有运气,即使我发现了一个类似的问题this,但没有希望。< / p>
然而,我尝试使用setOnTouchListener
进行滑动,但是它的毛刺并不像Start app
那样平滑滑动。
注意:我的代码与Custom Slide to unlock
有些相似我只是在寻找相同的滑动功能来锁定和解锁设备。
你的建议很明显。
答案 0 :(得分:0)
注意:使用9patch图像在图像视图中设置
public class MainActivity extends Activity implements OnTouchListener {
ImageView left,right;
int leftPosition,rightPosition;
boolean getSize = false;
int width;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
left = (ImageView)findViewById(R.id.left);
right = (ImageView)findViewById(R.id.right);
leftPosition = left.getRight();
rightPosition = right.getLeft();
width = getWindowManager().getDefaultDisplay().getWidth();
left.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
int eid = event.getAction();
switch (eid) {
case MotionEvent.ACTION_DOWN:
if(!getSize)
{
leftPosition = left.getRight();
rightPosition = right.getLeft();
getSize =true;
}
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) left.getLayoutParams();
int x = (int) event.getRawX();
if (x>leftPosition)
mParams.width = x;
left.setLayoutParams(mParams);
break;
case MotionEvent.ACTION_UP:
RelativeLayout.LayoutParams mParam = (RelativeLayout.LayoutParams) left.getLayoutParams();
mParam.width = leftPosition;
left.setLayoutParams(mParam);
break;
default:
break;
}
return true;
}
});
right.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
int eid = event.getAction();
switch (eid) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) right.getLayoutParams();
int x = (int) event.getRawX();
if (x<rightPosition)
mParams.width = width-x;
right.setLayoutParams(mParams);
break;
case MotionEvent.ACTION_UP:
RelativeLayout.LayoutParams mParam = (RelativeLayout.LayoutParams) right.getLayoutParams();
mParam.width = width - rightPosition;
right.setLayoutParams(mParam);
break;
default:
break;
}
return true;
}
});
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
} }