-8

我正在尝试测试本教程“Subsampling Scale Image View”中的代码以进行缩放图像捏合,但它在 .findViewById(id.imageView ); 上给出了一个错误;-无法解析符号..

我的 XML 布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

在我的MainActivity片段代码上有这个代码(在 onCreate 方法内):

public class MainActivity extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
        imageView.setImage(ImageSource.resource(R.drawable.abc));

    }
}

有人可以帮我吗?

在此先感谢 CAFC

4

2 回答 2

-1
 SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(R.id.imageView);
        imageView.setImage(ImageSource.resource(R.drawable.abc));

You have missed R.id.imageView

于 2016-09-28T17:32:00.403 回答
-4

快速解决方案:替换id.imageViewR.id.imageView.

What happens is, when you want to reference an ID, you go to the R (Resources) directory provided by android. You have to go to the resources directory (R), and then in there there's the id directory. Then there's your id. So, the final result is R.id.imageView.

于 2016-09-28T17:31:39.193 回答