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

时间:2020-12-18 23:44:33

I'm using Android Studio 1.2.2 I made a form activity and I want to insert an image. Where should I put the image? What changes I have to do in my mainactivity.java file?

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

2 个解决方案

#1


0  

You can use Android's ImageView tag. You need to write it inside .xml file of your activity. You can take reference of it from android's devloper's website.

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

In Andorid studio you can not directly drag & drop images.

在Andorid工作室中,您无法直接拖放图像。

It will be good for you to take reference of any example.Here is the ImageView xml code.

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

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

You can now make this ImageView reference in your MainActivity (Java) like below:

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

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

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

#2


0  

Take a look at the docs: http://developer.android.com/guide/topics/resources/drawable-resource.html

看看文档:http://developer.android.com/guide/topics/resources/drawable-resource.html

Commonly, you will want to use some of the qualifiers by screen density and provide each image at different resolutions, docs here, this way lets Android pick up the best image size and scale it to match the phone screen.

通常,您会希望按屏幕密度使用某些限定符并以不同的分辨率提供每个图像,这里的文档,这样Android就可以获取最佳图像大小并将其缩放以匹配手机屏幕。

Personally i use -nodpi and perform scalation by code, this way lets only have one copy of each image, and, gives you max control to position and size your images.

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

Hope this helps.

希望这可以帮助。

#1


0  

You can use Android's ImageView tag. You need to write it inside .xml file of your activity. You can take reference of it from android's devloper's website.

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

In Andorid studio you can not directly drag & drop images.

在Andorid工作室中,您无法直接拖放图像。

It will be good for you to take reference of any example.Here is the ImageView xml code.

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

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

You can now make this ImageView reference in your MainActivity (Java) like below:

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

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

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

#2


0  

Take a look at the docs: http://developer.android.com/guide/topics/resources/drawable-resource.html

看看文档:http://developer.android.com/guide/topics/resources/drawable-resource.html

Commonly, you will want to use some of the qualifiers by screen density and provide each image at different resolutions, docs here, this way lets Android pick up the best image size and scale it to match the phone screen.

通常,您会希望按屏幕密度使用某些限定符并以不同的分辨率提供每个图像,这里的文档,这样Android就可以获取最佳图像大小并将其缩放以匹配手机屏幕。

Personally i use -nodpi and perform scalation by code, this way lets only have one copy of each image, and, gives you max control to position and size your images.

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

Hope this helps.

希望这可以帮助。