我是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);
}
}
答案 0 :(得分:4)
您需要import android.widget.LinearLayout
。
答案 1 :(得分:1)
在Eclipse中只需执行CTRL + SHIFT + O即可自动修复导入,无论是添加所需的导入还是删除不需要的导入。
答案 2 :(得分:-1)
import android.widget.LinearLayout;
protected void onCreate(......
mainView = (LinearLayout) findViewById(R.id.LinearLayout1);
//Change the UI layout as `Linear-layout` and name it (my layout name is "LinearLayout1"