fitsSystemWindows失效无法自动padding

移动开发 码拜 8年前 (2016-09-17) 2805次浏览
题主实现一个类网易新闻的App,使用Tabhost+ViewPager实现。
同样的自定义Title布局,但发现Tab1可以实现正常的沉浸式,Tab3无论怎么样都不行,字体被状态栏覆盖。
style:

<style name="AppBaseTheme" parent="android:Theme.Holo.Light.NoActionBar">
</style>

main_activity:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"    
    tools:context=".ActivityMain" >
    <FrameLayout
        android:id="@+id/contentLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </FrameLayout>
    <android.support.v4.app.FragmentTabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#F6F6F6" >
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp" >
        </FrameLayout>
    </android.support.v4.app.FragmentTabHost>
</LinearLayout>

Tab1布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    
    <!-- 标题栏 -->
    <RelativeLayout  
        android:fitsSystemWindows="true"  
        android:clipToPadding="true"      
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="@color/title_color">
        <TextView
            android:id="@+id/tvTitle"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"            
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:text="Excerpt"
            android:textColor="@color/title_text_color"
            android:textSize="20sp" />
    </RelativeLayout>
    
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:textSize="30sp"/>
</LinearLayout>

Tab3布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">    
    <!-- 标题栏 -->
    <RelativeLayout  
        android:fitsSystemWindows="true"  
        android:clipToPadding="true"      
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="@color/title_color">
        <TextView
            android:id="@+id/tvTitle"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"            
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:text="Tab3"
            android:textColor="@color/title_text_color"
            android:textSize="20sp" />
    </RelativeLayout>
    <!-- 滚动标签栏 -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:orientation="horizontal" >
        <HorizontalScrollView
            android:id="@+id/hvMemoryLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
	    android:layout_toLeftOf="@+id/ivShowMore"
            android:scrollbars="none">
            <RadioGroup
                android:id="@+id/rgLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >
            </RadioGroup>
        </HorizontalScrollView> 
        <ImageView
            android:id="@+id/ivShowMore"
            android:layout_width="40dp"
            android:layout_height="35dp"
            android:layout_alignParentRight="true"
            android:background="#FF00FF00"
            android:contentDescription="Show more"
            android:scaleType="fitXY"
            android:src="@drawable/down_narrow" />       
    </RelativeLayout>
    <!-- 内容区域 -->
    <android.support.v4.view.ViewPager
        android:id="@+id/vpMemoryContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </android.support.v4.view.ViewPager>
</LinearLayout>

Tab1和Tab3的布局Title部分已使用BC比较过,无任何差异。但Tab1可以正常实现 title_color沉浸到状态栏,fitsSystemWindows也是可以自动padding的,而tab3颜色正常,但fitsSystemWindows却无法自动padding
请高手帮分析原因,拜谢

解决方案

10

 android:fitsSystemWindows=”true”

20

贴出来的布局没有问题,可能出现在别的地方

10

这个属性不是应该丢在activity的根目录上么?丢tab下不应该吧

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明fitsSystemWindows失效无法自动padding
喜欢 (0)
[1034331897@qq.com]
分享 (0)