[英]How to resize imageview on XML file from Java File? (Android)
[英]imageview source in the java file and the xml file?
看下面的代碼;
ImageView theImageView = (ImageView) theView.findViewById(R.id.imageView1);
theImageView.setImageResource(R.drawable.dot);
如果我們在xml文件中建立了圖像的源(android:src),第二行是否必要? XML如下所示;
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="25dp"
android:src="@drawable/dot"
android:id="@+id/imageView1"/>
不。您可以使用XML或Java代碼來完成。 您不必重復兩次。
如果您已經定義了ImageView並設置了圖像,那么您甚至不必在Java代碼(第一行)中獲取它的引用,除非您想要更改某些內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.