【发布时间】:2017-03-25 22:08:50
【问题描述】:
我有一个包含 1 个用作背景的图像的 HorizontalScrollView。此图像可以从左到右滚动。我想将其他图像视图放在背景图像上,但不让它们随之滚动。目前,如果我在上面放置另一个图像视图,当我滚动图像时也会出现。
最左边的滚动视图:
最右边的滚动视图:
XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_rear_gunner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:focusable="true"
tools:context="com.example.mr_br.ibcc_bomber_command.rear_gunner">
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_alignParentTop="true"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent" app:srcCompat="@drawable/background_scroll_2"
android:id="@+id/scrollView" android:layout_centerVertical="true"
android:scaleType="centerCrop"
/>
</HorizontalScrollView>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:focusable="true"
tools:context="com.example.mr_br.ibcc_bomber_command.rear_gunner">
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" app:srcCompat="@drawable/placeholder_bomber"
android:id="@+id/enemy" android:layout_centerVertical="true"
/>
</RelativeLayout>
在 android 中使用布局非常新。希望我把我的问题说清楚,如果不是,我会道歉,如果被问到,我会尽力澄清。我知道这可能与我正在使用的布局以及它们的子布局和父布局有关,但就像我说的新的一样。
【问题讨论】:
-
抱歉,无法解决您的问题。如果敌人是飞机,它不会根据您的图像随着背景滚动。预期的结果是什么?
-
飞机是敌人是的。我想要的结果是,当我说向右滚动时,飞机保持在左侧的起始位置并离开屏幕,如果我说向左滚动,它又回到屏幕上。
-
也许创建一个大于屏幕尺寸的视图可以解决这个问题?
标签: java android xml image android-layout