-1

我是 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);  
 } 
}
4

3 回答 3

4

你需要import android.widget.LinearLayout

于 2013-02-28T02:38:59.200 回答
1

在 Eclipse 中,只需执行 CTRL + SHIFT + O,它就会自动修复您的导入,无论是添加需要的还是删除不必要的。

于 2013-02-28T02:41:23.410 回答
-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"
于 2014-02-11T07:16:13.690 回答