我的第二个工具栏存在很大的问题,应该在我的视图底部。它只是显示出来,我花了好几个小时试图使其工作,但无法弄清楚为什么我的片段中的可滚动GridList掩盖了它......
看看我的main_activity.xml
:
<?xml version="1.0" encoding="utf-8"?>
<!-- This DrawerLayout has two children at the root -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/main_container"
>
<!-- The ActionBar displayed at the top -->
<include
layout="@layout/toolbar_top"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- The main content view where fragments are loaded -->
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/background_dark"/>
<!-- The Toolbar displayed at the bottom -->
<include
layout="@layout/toolbar_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->
<android.support.design.widget.NavigationView
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:id="@+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/black_90percent"
app:menu="@menu/drawer_view"
app:itemTextAppearance="@style/TextAppearance.AppCompat.Subhead"
app:itemIconTint="@drawable/drawer_item"
app:itemTextColor="@drawable/drawer_item"
app:itemBackground="@drawable/drawer_item_background"
app:elevation="16dp"
/>
</android.support.v4.widget.DrawerLayout>
这是我的animation_fragment.xml(这就是加载到main_activity.xml中的片段的布局)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context="com.example.pymdev.pym.AnimationFragment">
<GridView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="4dp"
android:numColumns="2"
android:verticalSpacing="4dp" />
<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</FrameLayout>
我已经非常接近,带有图像的网格工作,可滚动项目的所有样式都很好。唯一的问题是底部工具栏。请帮忙,我完全被困在这里。
答案 0 :(得分:2)
尝试使用RelativeLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_container">
<!-- The ActionBar displayed at the top -->
<include
layout="@layout/toolbar_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"/>
<!-- The main content view where fragments are loaded -->
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/background_dark"
android:layout_below="@id/toolbar_top"
android:layout_above="@id/toolbar_bottom"/>
<!-- The Toolbar displayed at the bottom -->
<include
layout="@layout/toolbar_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
答案 1 :(得分:1)
使用网格视图高度的布局权重:
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/main_container"
>
<!-- The ActionBar displayed at the top -->
<include
layout="@layout/toolbar_top"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- The main content view where fragments are loaded -->
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/background_dark"/>
<!-- The Toolbar displayed at the bottom -->
<include
layout="@layout/toolbar_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
这样您的网格视图就不会使用整个屏幕。