开发者

Android: It is possible to load an activity as a view?

开发者 https://www.devze.com 2023-02-28 12:43 出处:网络
For example like, View v = MapActivity.class; below works as an activity 开发者_如何学Cbut it doesnt work when i try to build the view with an adapter.

For example like,

View v = MapActivity.class;

below works as an activity 开发者_如何学Cbut it doesnt work when i try to build the view with an adapter.

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


From 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 is not part of the hierarchy. View v = MapActivity.class; doesn't make much sense.

What you can do, if View is part of an Activity in the same app, is:

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

Assuming that you gave an id zoomain to your main layout.

Alternatively, you can create your own custom layout, implementing the custom Listener, and then reuse it in more than one Activity.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号