我想顯示視圖,屏幕上的座標取決於傳感器數據。我設法顯示一個文本,如that SO question中所解釋的,我現在試圖展示一些TextViews,但是在我的TextViews上調用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
在這裏,我得到的傳感器的數據,更新我的ARViews座標,希望吸引他們......
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
}