繁体   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