【问题标题】: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 barAndroid - 为什么我的图像视图占据了大部分屏幕?我希望它占据自定义应用栏下方的所有空间
【发布时间】:2021-07-17 18:10:20
【问题描述】:

所以你可以从图片中看到,当我想要它时,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>   
    

【问题讨论】:

  • 你的 ImageView 在 ViewPager 中吗?如果是,请将其添加到您的视图寻呼机布局 android : layout_below ="@id/app_bar_layout"

标签: java android xml android-layout android-viewpager


【解决方案1】:

您能否发布您的父布局(以及相对布局)。 我认为它没有得到适当的约束。设置您的父级相对布局高度以匹配父级。

同时设置android:layout_alignParentTop="false"

【讨论】:

    【解决方案2】:

    您需要从 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> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      • 2020-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多