Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 要解锁的自定义幻灯片_Android_Android Imageview_Android Sliding - Fatal编程技术网

Android 要解锁的自定义幻灯片

Android 要解锁的自定义幻灯片,android,android-imageview,android-sliding,Android,Android Imageview,Android Sliding,您好,我正在尝试开发一个自定义锁定屏幕,我想用图像视图替换幻灯片以解锁,如图所示 这就是我迄今为止所尝试的 我在屏幕的左角放置了一个图像,并使用onTouchListner将图像水平拖动到下面的代码中 left_Locker.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { int eid = ev

您好,我正在尝试开发一个自定义锁定屏幕,我想用图像视图替换幻灯片以解锁,如图所示

这就是我迄今为止所尝试的

我在屏幕的左角放置了一个图像,并使用onTouchListner将图像水平拖动到下面的代码中

left_Locker.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                int eid = event.getAction();
                switch (eid) {
                case MotionEvent.ACTION_DOWN:
                    toastText.setVisibility(View.VISIBLE);
                    toastText.setTextColor(Color.BLACK);
                    toastText.setText("Slide to Unlock");
                    break;
                case MotionEvent.ACTION_MOVE:
                    RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) left_Locker.getLayoutParams();
                    int x = (int) event.getRawX();
                    mParams.leftMargin = x - 50;
                    left_Locker.setLayoutParams(mParams);
                    break;
                case MotionEvent.ACTION_UP:
                        toastText.setVisibility(View.GONE);
                        break;
                default:
                    break;
                }
                return true;
            }
        });
图像确实是水平移动的,但我所看到的是要让图像背景也像上图所示那样被拖动。我使用ImageView是否在正确的轨道上

下面是我尝试过的图像


我可以水平移动图像,但如何在滚动时获得背景???

我认为您应该尝试类似的方法

还有另一种方法。使用相对布局设置seekbar下方的背景图像,并使其progressbar透明,图像为拇指

接下来,根据seekbar进度按比例设置图像宽度


可能还有另一种解决方案,您可以在imageview上使用ontouchlistener,每次只更改x,保留y不变,并像上面的方法一样更改背景。

我对您的代码进行了一些修改,我实现了

下面是将屏幕末端的图像向两侧滑动的代码(
Left&Right

为此,您必须对要滑动的两侧使用图像

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:
               /* toastText.setVisibility(View.VISIBLE);
                toastText.setTextColor(Color.BLACK);
                toastText.setText("Slide to Unlock");*/

                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:
               /* toastText.setVisibility(View.VISIBLE);
                toastText.setTextColor(Color.BLACK);
                toastText.setText("Slide to Unlock");*/
                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:
                    //toastText.setVisibility(View.GONE);
                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;
}   }
public类MainActivity扩展了活动实现到TouchListener上{
图像视图左、右;
int leftPosition,righposition;
布尔getSize=false;
整数宽度;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
左=(ImageView)findViewById(R.id.left);
右=(ImageView)findViewById(R.id.right);
leftPosition=left.getRight();
rightPosition=right.getLeft();
宽度=getWindowManager().getDefaultDisplay().getWidth();
left.setOnTouchListener(新的OnTouchListener(){
公共布尔onTouch(视图v,运动事件){
int eid=event.getAction();
开关(eid){
case MotionEvent.ACTION\u DOWN:
/*toastText.setVisibility(View.VISIBLE);
toast text.setTextColor(Color.BLACK);
toast text.setText(“滑动解锁”)*/
如果(!getSize)
{
leftPosition=left.getRight();
rightPosition=right.getLeft();
getSize=true;
}
打破
case MotionEvent.ACTION\u移动:
RelativeLayout.LayoutParams mParams=(RelativeLayout.LayoutParams)left.getLayoutParams();
int x=(int)event.getRawX();
如果(x>左位置)
mParams.width=x;
左。设置布局参数(mParams);
打破
case MotionEvent.ACTION\u UP:
RelativeLayout.LayoutParams mParam=(RelativeLayout.LayoutParams)left.getLayoutParams();
mParam.width=左位置;
左。设置布局参数(mParam);
打破
违约:
打破
}
返回true;
}
});
right.setOnTouchListener(新的OnTouchListener(){
公共布尔onTouch(视图v,运动事件){
int eid=event.getAction();
开关(eid){
case MotionEvent.ACTION\u DOWN:
/*toastText.setVisibility(View.VISIBLE);
toast text.setTextColor(Color.BLACK);
toast text.setText(“滑动解锁”)*/
打破
case MotionEvent.ACTION\u移动:
RelativeLayout.LayoutParams mParams=(RelativeLayout.LayoutParams)right.getLayoutParams();
int x=(int)event.getRawX();

如果(X请留下评论。为什么投票被否决。据我所知,这是一个有效的编程问题。嘿,伙计,我正在寻找与此完全相同的问题。你能帮我吗?你有你的解决方案吗?我在过去3天中通过各种不同的方式寻找这个问题,但没有找到正确的方法或解决方案。你能帮我做些什么吗?@Yog Guru我还在寻找解决方案。如果你发现一个Thanks,请回答这个问题。如果用户单击progressDrawable,拇指会移动。如何限制它。我希望seekbar只使用拇指移动。尝试在onprogresschange和onstarttracking中设置一个条件,将进度设置为零,除非初始程序ss小于10。@contactmeandroid你试过这个吗?对你有用吗?