0

Activity以全屏模式运行。由于海拔在Kitkat中缺失,ViewPager高于ToolbarViewPager kitkat后面的工具栏

这里是我的布局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/PhotoPager_Layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:theme="@style/ThemeOverlay.AppCompat" 
    > 
    <include 
     android:id="@+id/toolbar" 
     layout="@layout/toolbar" 
     android:background="@color/md_dark_appbar" 
     android:windowActionBarOverlay="true" 
     /> 

    <com.horaapps.leafpic.Views.HackyViewPager 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/photos_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 
</RelativeLayout> 

这是什么样子: screenshot

我如何能解决这个问题有什么建议?

回答

1

RelativeLayout中的项目是z顺序的。 Defaulr oder是:较早的项目后面的项目。 您的工具栏首先位于RelativeLayout中,因此它位于任何其他视图的后面。

有三种解决方案。你可以使用它们中的任何一个。在RelativeLayout的

  1. 重新排序的看法:移动toolbat到结束:

    <?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/PhotoPager_Layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:theme="@style/ThemeOverlay.AppCompat" 
    > 
    
        <com.horaapps.leafpic.Views.HackyViewPager 
         xmlns:android="http://schemas.android.com/apk/res/android" 
         android:id="@+id/photos_pager" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"/> 
    
        <include 
         android:id="@+id/toolbar" 
         layout="@layout/toolbar" 
         android:background="@color/md_dark_appbar" 
         /> 
    </RelativeLayout> 
    
  2. 呼叫toolbar.bringToFront()在某处的onCreate()(如果您使用此布局的活动)。例如:

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    
        setContentView(R.layout.layout_activity);// your resource name here 
    
        View toolbar = findViewById(R.id.toolbar); 
        toolbar.bringToFront(); 
    
        .... 
    } 
    
  3. 呼叫的ViewGroup :: bringChildToFront的某处的onCreate工具栏视图的父。如果您使用此布局在活动的onCreate,则代码应该是:

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        setContentView(R.layout.layout_activity);// your resource name here 
        RelativeLayout root = findViewById(R.id.PhotoPager_Layout); 
        View toolbar = findViewById(R.id.toolbar); 
        root.bringChildToFront(toolbar); 
    
        .... 
    } 
    
+0

所有解决方案的作品。谢谢! – dnld

0

您最好为您的HackyViewPager自定义视图提供代码,以更好地理解您的问题。但我的猜测是,在那里你不会考虑不同的操作系统版本计算底部的软按钮(HOME,BACK,MENU)。从棒棒糖开始,软按钮是屏幕的一部分,而在早期版本中,它们不在屏幕中。 希望这有助于。

+0

的'HackyViewPager'并没有什么奇怪的,这是没问题的。 – dnld

相关问题