我刚刚开始学习android。我不知道如何改变一个人的形象ImageView
?即它有一些在布局中设置的图像,但我想通过编码更改该图像我应该怎么做?
这是 xml 文件
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#cc8181"
>
<ImageView
android:id="@+id/image"
android:layout_width="50dip"
android:layout_height="fill_parent"
android:src="@drawable/icon"
android:layout_marginLeft="3dip"
android:scaleType="center"/>
感谢回复。
如果您使用 xml 文件创建 imageview,请按照以下步骤操作。
解决方案一:
第 1 步:创建 XML 文件
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#cc8181"
>
<ImageView
android:id="@+id/image"
android:layout_width="50dip"
android:layout_height="fill_parent"
android:src="@drawable/icon"
android:layout_marginLeft="3dip"
android:scaleType="center"/>
</LinearLayout>
第 2 步:创建活动
ImageView img= (ImageView) findViewById(R.id.image);
img.setImageResource(R.drawable.my_image);
解决方案2:
如果您从 Java 类创建了 imageview
ImageView img = new ImageView(this);
img.setImageResource(R.drawable.my_image);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)