画面上で座標を合わせるビューを表示しようとすると、センサのデータに依存します。私はthat SO questionで説明されているテキストを表示することができましたが、代わりにTextViewsを表示しようとしていますが、TextViewsでinvalidate()を呼び出すと描画されません...invalidate()を実行しているときにTextViewが描画されない
誰かが助けることができますか?
おかげ
ARView.java
public class ARView extends TextView
{
public String name;
public float azimuth;
public float distance;
public float inclination;
public Location location;
public ARView(Context context)
{
super(context);
setText(name);
}
}
ARActivity.java
ここで私は、その親ビューに私のARViewを追加します。
public class ARActivity extends Activity{
private ARLayout ar;
private CBCameraView cv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ar = new ARLayout(getApplicationContext());
cv = new CBCameraView(this.getApplicationContext());
FrameLayout rl = new FrameLayout(this.getApplicationContext());
rl.addView(cv, GlobalVars.screenWidth, GlobalVars.screenHeight);
rl.addView(ar, GlobalVars.screenWidth, GlobalVars.screenHeight);
setContentView(rl);
Location location = new Location("me");
location.setLatitude(41.371974);
location.setLongitude(2.166978);
ARView fs = new ARView(this.getApplicationContext());
fs.azimuth = 0;
fs.inclination = 0;
fs.location = location;
fs.name="Bar seco";
ar.addARView(fs);
}
}
ARLayout.java
ここで私はこれが解決策である場合、私は知らない
public class ARLayout extends View implements LocationListener, SensorEventListener
{
// ...
@Override
public void onSensorChanged(SensorEvent event) {
// here I get sensors data and update my views
for(int i=0; i<nArViews; i++)
{
ARView view = arViews.get(i);
int x = ...; // new x coordinate of my ARView
int y = ...; // new y coordinate of my ARView
view.layout(x, y, view.getBottom(), view.getRight()); // set new coordinates to my ARViews
}
invalidate(); // draw my ARLayout
}
public void onDraw(Canvas c)
{
for(int i=0; i<nArViews; i++)
{
ARView view = arViews.get(i);
view.invalidate(); // I thought it would draw my ARViews, but it doesn't :(
}
}
// more stuff
}