2016-09-28 59 views
-9

我試圖測試本教程「Subsampling Scale Image View」中的代碼來縮小圖像縮小,但它在.findViewById(id。imageView); - 不能解析符號 ..FindViewById上的錯誤 - Subsampling Scale Image View - Android

我的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

回答

-5

快速的解決方案:更換id.imageViewR.id.imageView

會發生什麼是,當你想引用一個ID,你去到由android提供的R(資源)目錄。你必須去資源目錄(R),然後在那裏有id目錄。然後是你的ID。所以最後的結果是R.id.imageView

+0

-6 downvotes ...哇 –

+0

我不知道他們爲什麼downvoted這個答案的6倍。 Upvoted它,什麼是負載的BS。 – Jordy

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

你已經錯過了R.id.imageView