[英]How and Where to define this ImageView in xml?
在此Android導航圖標-個人資料圖片而不是漢堡包圖標 stackoverfolw post
ImageView profileImage = (ImageView) binding.navView.getHeaderView(0).findViewById(R.id.iv_profile_image);
如何在哪里定義哪個xml文件中的R.id.iv_profile_image
?
在您鏈接的示例中找不到XML代碼。 但是,我注意到Activity的onCreate()方法中的以下行。 這將表明正在使用的XML文件稱為activity_maps.xml。 這很可能是放置ImageView的位置。
binding = DataBindingUtil.setContentView(this, R.layout.activity_maps);
假設這個假設是正確的,則可以將ImageView聲明為這樣的內容。 XML中“ where”的答案取決於XML,這是一種聲明性語言。
<ImageView android:id="@+id/iv_profile_image"
android:layout_width="60dp"
android:layout_height="60dp"
...
android:contentDescription="@string/to_replace" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.