2011-04-26 134 views
0

例如like,Android:可以将活动加载为视图吗?

查看v = MapActivity.class;

下面的工作作为一项活动,但它不工作时,我尝试用适配器生成视图。

setContentView(R.layout.zoommain); 

mZoomControl = new DynamicZoomControl(); 

mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image800x600); 

mZoomListener = new LongPressZoomListener(getApplicationContext()); 
mZoomListener.setZoomControl(mZoomControl); 

//not working... loading custom view 
mZoomView = (ImageZoomView)findViewById(R.id.zoomview); 
//mZoomView = (ImageZoomView)context.getResources().findViewById(R.id.zoomview); 
//context.getResources() 
mZoomView.setZoomState(mZoomControl.getZoomState()); 
mZoomView.setImage(mBitmap); 
mZoomView.setOnTouchListener(mZoomListener); 

mZoomControl.setAspectQuotient(mZoomView.getAspectQuotient()); 

resetZoomState(); 

回答

0

http://developer.android.com/reference/android/app/Activity.html

java.lang.Object 
    ↳ android.content.Context 
     ↳ android.content.ContextWrapper 
      ↳ android.view.ContextThemeWrapper 
       ↳ android.app.Activity 

View不是层次结构的一部分。 View v = MapActivity.class;没有多大意义。

你能做什么,如果视图是在同一个应用程序的活动的一部分,是:

View view = findViewById(R.id.zoommain); 

假设你给一个id zoomain到主布局。

或者,您可以创建自己的自定义布局,实现自定义Listener,然后在多个Activity中重复使用它。

+0

非常感谢。这是我需要的解释。 – 2011-04-26 13:26:53

相关问题