带传感器的视差3D效果壁纸

时间:2019-04-05 12:43:40

标签: android 3d parallax sensormanager android-wallpaper

我想创建具有三层图像的视差3d效果墙纸应用程序。我需要一些技巧来开发视差效果壁纸。我可以在应用程序内显示视差效果,同样,我必须在墙纸中设置。给我任何想法吗? 此活动代码:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class Parallaxactivity extends AppCompatActivity {
    private ParallaxView mParallaxView;
    private ParallaxView mParallaxView2;
    private ParallaxView mParallaxView3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.parallaxlayout);
        mParallaxView = (ParallaxView) findViewById(R.id.parallax_view);
        mParallaxView2 = (ParallaxView) findViewById(R.id.parallax_view_2);
        mParallaxView3 = (ParallaxView) findViewById(R.id.parallax_view_3);


        initParallaxViews();
    }

    private void initParallaxViews() {
        mParallaxView.init();
        mParallaxView.setMinimumMovedPixelsToUpdate(ParallaxView.DEFAULT_MIN_MOVED_PIXELS );
        mParallaxView.setMovementMultiplier(ParallaxView.DEFAULT_MOVEMENT_MULTIPLIER );
        mParallaxView2.init();
        mParallaxView2.setMinimumMovedPixelsToUpdate(ParallaxView.DEFAULT_MIN_MOVED_PIXELS * 2);
        mParallaxView2.setMovementMultiplier(ParallaxView.DEFAULT_MOVEMENT_MULTIPLIER * 2);
        // mParallaxView.registerSensorListener();
        mParallaxView3.init();
        mParallaxView3.setMinimumMovedPixelsToUpdate(ParallaxView.DEFAULT_MIN_MOVED_PIXELS * 3);
        //   mParallaxView2.registerSensorListener();
        mParallaxView3.setMovementMultiplier(ParallaxView.DEFAULT_MOVEMENT_MULTIPLIER * 3);
        //  mParallaxView3.registerSensorListener();
    }

    @Override
    protected void onResume() {
        mParallaxView.registerSensorListener();
        mParallaxView2.registerSensorListener();
        mParallaxView3.registerSensorListener();
        super.onResume();
    }

    @Override
    protected void onPause() {
        mParallaxView.unregisterSensorListener();
        mParallaxView2.unregisterSensorListener();
        mParallaxView3.unregisterSensorListener();
        super.onPause();
    }
}

0 个答案:

没有答案