我是 Android 新手,我正在尝试 Pinch to Zoom 代码。我在此行收到错误“LinearLayout 无法解析为类型”。mainView =(LinearLayout)findViewById(R.id.linearLayout); 这是下面的代码,你能帮我解决这个问题吗?谢谢您的帮助。
package com.zoomlayout;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.PointF;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ZoomLayout extends Activity {
View mainView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zoom_layout);
mainView =(LinearLayout)findViewById(R.id.linearLayout); //got the error here
Button buttonZoomOut = (Button)findViewById(R.id.buttonZoomOut);
Button buttonNormal = (Button)findViewById(R.id.buttonNormal);
Button buttonZoomIn = (Button)findViewById(R.id.buttonZoomIn);
buttonZoomOut.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
zoom(0.5f,0.5f,new PointF(0,0));
}
});
buttonNormal.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
zoom(1f,1f,new PointF(0,0));
}
});
buttonZoomIn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
zoom(2f,2f,new PointF(0,0));
}
});
}
/** zooming is done from here */
public void zoom(Float scaleX,Float scaleY,PointF pivot){
mainView.setPivotX(pivot.x);
mainView.setPivotY(pivot.y);
mainView.setScaleX(scaleX);
mainView.setScaleY(scaleY);
}
}