Jak*_*itz 7 android android-fragments android-toolbar
我最近开始搞乱AppCompat 21的新组件并实现Material Design.目前,我有一个带有工具栏的ActionBarActivity,并且我试图让它托管一个包含TextView项目的RecyclerView的片段(仅用于测试Recycler).我正在显示项目,但每个视图中的文本都被截断,整个Recycler覆盖工具栏,如下所示:

如您所见,有三个TextView.他们的文字被中途切断,它覆盖了工具栏(我知道没有标题).TextView项目布局包含在RecyclerView布局中,这是Fragment的布局.父Activity有一个FrameLayout - > Toolbar,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>
我知道它必须是简单的东西,但我已经被困了一段时间,尝试各种各样的事情无济于事.
Ram*_*ula 22
请不要忘记将app:layout_behavior ="@ string/appbar_scrolling_view_behavior"添加到您的内容布局
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        <android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
   </android.support.design.widget.AppBarLayout>
    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
| 归档时间: | 
 | 
| 查看次数: | 9224 次 | 
| 最近记录: |