android – 片段内容覆盖工具栏

我最近开始搞乱AppCompat 21的新组件并实现Material Design.目前,我有一个带有工具栏的ActionBaractivity,并且我试图让它托管一个包含TextView项目的RecyclerView的片段(只是为了测试Recycler).我正在显示项目,但每个视图中的文本都被截断,整个Recycler覆盖工具栏,如下所示:

如您所见,有三个TextView.他们的文字被中途切断,它覆盖了工具栏(我知道没有标题). TextView项目布局包含在RecyclerView布局中,这是Fragment的布局.父Activity有一个FrameLayout – >工具栏,FrameLayout.我将Fragment插入Activity的子FrameLayout.这是XML

Recycler中的每个视图:

<TextView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/textview"
  android:layout_width="match_parent"
  android:layout_height="48dp"
  android:fontFamily="sans-serif"
  android:paddingTop="16dp"
  android:paddingBottom="20dp"
  android:textSize="16sp"/>

Recycler布局,即片段的布局:

<android.support.v7.widget.RecyclerView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/recycler_tasks"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="stuff.MainActivity$TaskFragment">
</android.support.v7.widget.RecyclerView>

和父Activity的布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/container"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity"
  tools:ignore="MergeRootFrame">

  <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

  <FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

</FrameLayout>

我知道它一定是简单的东西,但我已经被困了一段时间,尝试各种各样的事无济于事.

解决方法

使用RelativeLayout而不是FrameLayout作为顶级父级.然后只需为工具栏添加layout_above等依赖项,或为片段容器添加layout_below.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...