我有一个包含 1 个用作背景的图像的水平滚动视图。此图像可以从左向右滚动。我想将其他图像视图放在背景图像上,但不要让它们随它滚动。目前,如果我在此之上放置另一个图像视图,当我滚动图像时也会出现。
最左边的滚动视图:
最右侧的滚动视图:
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 中使用布局非常新。希望我说清楚我的问题,如果不是我道歉,如果被问到,我会尽力澄清。我知道这可能与我使用的布局以及他们的孩子和父母的布局有关,但就像我说的那样。
HorizontalSCrollView 只能有一个子级,但该子级可以是另一种布局,因此您可以添加任意数量的 ImageView。
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="3000dp"
android:layout_height="match_parent"
android:background="#a30"
/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#aa0"
/>
</RelativeLayout>
</HorizontalScrollView>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句