我想在我的android活动中输入图像。我应该把图像放在哪里?

时间:2015-09-28 06:08:23

标签: android android-layout android-activity android-imageview android-image

我使用Android Studio 1.2.2我做了一个表单活动,我想插入一个图像。我应该把图像放在哪里?我必须在mainactivity.java中做些什么改变  文件?

2 个答案:

答案 0 :(得分:0)

您可以使用Android的ImageView标记。您需要在活动的.xml文件中写入它。你可以从android的devloper网站上参考它。

在Andorid工作室,你不能直接拖拽&放下图片。

您可以参考任何示例。这是ImageView xml代码。

 <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/android" />

您现在可以在MainActivity(Java)中创建此ImageView引用,如下所示:

ImageView imageView; imageView =(ImageView)findViewById(R.id.imageView1);

答案 1 :(得分:0)

查看文档:{​​{3}}

通常,您需要按屏幕密度使用某些限定符,并以不同的分辨率提供每个图像,文档http://developer.android.com/guide/topics/resources/drawable-resource.html,这样便可让Android获取最佳图像大小并将其缩放以匹配手机屏幕

我个人使用-nodpi并通过代码执行scalation,这样每个图像只能有一个副本,并且可以让你最大程度地控制图像的位置和大小。

希望这有帮助。

相关问题