Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying Compass At specific location on Device
    primarykey
    data
    text
    <p>I want to display the compass(Image View) on device at a specific location.I tried Like this below code to display the compass view on device but the thing is i need to display at Specific location and small view only but it occupies entire screen space.Can you help me to fix an compass image at specific location.Using this line of code i am getting an image form Drawable folder. this.setImageResource(R.drawable.compassrose); So how to fix that image at specific location.</p> <pre><code>Class1:- public class Compass extends Activity implements SensorListener { SensorManager sensorManager; static final int sensor = SensorManager.SENSOR_ORIENTATION; Rose rose; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //http://ofps.oreilly.com/titles/9781449390501/Android_System_Services.html // Set full screen view getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); //FLAG_FULLSCREEN //FLAG_SCALED rose = new Rose(this); setContentView(rose); // get sensor manager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); } // register to listen to sensors @Override public void onResume() { super.onResume(); sensorManager.registerListener(this, sensor); } // unregister @Override public void onPause() { super.onPause(); sensorManager.unregisterListener(this); } // Ignore for now public void onAccuracyChanged(int sensor, int accuracy) { } // Listen to sensor and provide output public void onSensorChanged(int sensor, float[] values) { if (sensor != Compass.sensor) return; int orientation = (int) values[0]; rose.setDirection(orientation); } } Class 2:- public class Rose extends ImageView { Paint paint; int direction = 0; public Rose(Context context) { super(context); paint = new Paint(); paint.setColor(Color.WHITE); paint.setStrokeWidth(2); paint.setStyle(Style.STROKE); this.setImageResource(R.drawable.compassrose); } @Override public void onDraw(Canvas canvas) { int height = this.getHeight(); int width = this.getWidth(); canvas.rotate(direction, width / 2, height / 2); super.onDraw(canvas); } public void setDirection(int direction) { this.direction = direction; this.invalidate(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload