簡體   English   中英

Android Studio:布局層次結構問題

[英]Android Studio: Layout hierarchy problems

我有一個horizo​​ntalScrollView包含1張用作背景的圖像。 該圖像可以從左到右滾動。 我想將其他imageview放在背景圖像上,但不要讓它們隨背景滾動。 目前,如果我在其上放置另一個imageview,則在滾動圖像時也會出現。

最左側的滾動視圖:

在此處輸入圖片說明

最右側的滾動視圖:

在此處輸入圖片說明

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中使用布局非常新。 希望我能清楚地表達我的問題,如果沒有的話我會道歉,如果有要求,我會盡力澄清。 我知道這可能與我使用的布局以及孩子和他們的父母的布局有關,但就像我對它所說的那樣。

Horizo​​ntalSCrollView只能有一個子視圖,但是該子視圖可以是另一個布局,因此您可以添加所需的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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM