簡體   English   中英

Android - 為什么我的圖像視圖占據了大部分屏幕? 我希望它占據自定義應用欄下方的所有空間

[英]Android - Why is my image view taking up most of the screen? I want it to take up all the space beneath the custom app bar

因此,正如您從圖像中看到的那樣,當我想要它時,imageView 幻燈片圖片幾乎占據了整個屏幕:

  1. 從操作欄下方開始(您可以看到自定義應用欄的淺紫色)

  2. 占用下面的所有空間。 如果有人有任何想法,我將不勝感激,謝謝。 圖片: https://imgur.com/a/FPBCYH9

     <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/TextColor" android:id="@+id/app_bar_layout" > <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" style="@style/TextColor" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@color/colorPrimaryDark" android:theme="@style/ThemeOverlay.AppCompat.Dark" /> </com.google.android.material.appbar.AppBarLayout> <.-- viewpager to show images --> <androidx.viewpager.widget:ViewPager android:id="@+id/viewPagerMain" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentTop="true" /> </RelativeLayout>

您能否發布您的父布局(以及相對布局)。 我認為它沒有得到適當的約束。 設置您的父級相對布局高度以匹配父級。

同時設置android:layout_alignParentTop="false"

您需要從 ViewPager 中刪除android:layout_alignParentTop="true" ,並將其替換為android:layout_below="@+id/app_bar_layout"

 <com.google.android.material.appbar.AppBarLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     style="@style/TextColor"
     android:id="@+id/app_bar_layout" >

     <androidx.appcompat.widget.Toolbar
         android:id="@+id/toolbar"
         style="@style/TextColor"
         android:layout_width="match_parent"
         android:layout_height="?attr/actionBarSize"
         android:background="@color/colorPrimaryDark"


     android:theme="@style/ThemeOverlay.AppCompat.Dark" />
     </com.google.android.material.appbar.AppBarLayout>


     <!-- viewpager to show images -->
     <androidx.viewpager.widget.ViewPager
         android:id="@+id/viewPagerMain"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentStart="true"
         android:layout_below="@+id/app_bar_layout"/>

 </RelativeLayout> 

暫無
暫無

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

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