2012-03-05 4 views
0

コンパス(イメージビュー)を特定の場所に表示するとします。試しました。デバイスのコンパスビューを表示するにはこのコードのようにしますが、具体的に表示する必要があります場所と小さなビューのみが、画面全体のスペースを占めています。私は特定の場所でコンパス画像を修正するのを助けることができます。コードのこの行を使用して、私は画像フォームDrawableフォルダを取得しています。 this.setImageResource(R.drawable.compassrose);どのように特定の場所でそのイメージを修正するか。コンパスを表示するデバイスの特定の場所に

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(); 
    } 

} 

答えて

0

ImageViewをAndroidレイアウトに配置する方法をお尋ねしますか? XMLで試したことがありますか、またはプログラムで設定する必要がありますか?

あなただけのImageViewのを配置しようとしている場合は、レイアウトのチュートリアルの一部を通過してみてください:http://developer.android.com/resources/tutorials/views/index.html

ない場合は、あなたの質問に詳細を追加してください

2
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    rose = new Rose(this); 
    txtorientation = (TextView) findViewById(R.id.textView1); 
    compassLayout = (RelativeLayout)findViewById(R.id.CompassLayout); 
    compassLayout.addView(rose); 
    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); 
    sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); 
    Log.d("Compass", "onCreated"); 
} 
関連する問題