XML 图片切换
XML image switching
我是编码新手,我正在从事文本冒险,并希望图像视图根据位置更改图像,我想知道它是如何工作的,以及为什么这个解决方案不起作用。根据玩家位置来做会更好吗?我遇到了一些麻烦,在哪里可以找到相关信息。
谢谢
<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
文件夹中
要获取纬度和经度位置,您可以按照此操作 link https://javapapers.com/android/get-current-location-in-android/
我是编码新手,我正在从事文本冒险,并希望图像视图根据位置更改图像,我想知道它是如何工作的,以及为什么这个解决方案不起作用。根据玩家位置来做会更好吗?我遇到了一些麻烦,在哪里可以找到相关信息。 谢谢
<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
文件夹中
要获取纬度和经度位置,您可以按照此操作 link https://javapapers.com/android/get-current-location-in-android/