我是编码的新手,我正在从事文字冒险,并且希望imageview根据位置更改图像,我想知道它如何工作以及为什么这种解决方案不起作用。根据玩家的位置来做会更好吗?遇到问题时,我可以在哪里找到有关此信息。谢谢
<room>
<east>1</east>
<description>Room 1(0)</description>
<ImageView
android:id="@+id/ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bedroom"
/>
</room>
<room>
<east>2</east>
<west>0</west>
<description>Room 2(1)</description>
<ImageView
android:id="@+id/imagePlace1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/living"
/>
</room>
<room>
<west>1</west>
<description>Room 3(2)</description>
<ImageView
android:id="@+id/imagePlace2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/kitchen"
/>
</room>```
如果仅使用1个imageview并根据位置更改图像,那将是很好的选择>
要更改图像,请使用以下Java代码:
imageview_object.setImageResource(R.drawable.image_name);
确保您的图像位于
res/drawable
文件夹中
要获取纬度和经度的位置,您可以点击此链接https://javapapers.com/android/get-current-location-in-android/