我有这个3列可垂直滚动的GridView,带有导航抽屉用于导航,但是在操作栏和网格的顶行之间有一个很大的空白区域。这是布局。我添加了android:layout_alignParentTop =“true”,但没关系。空白区域具有操作栏的确切高度,所以这可能意味着什么。点击任何一部分空白区域会突出显示其边框,使其与放置的列对齐。点击3个空格中的任何一个都可以转到第一个缩略图的完整图像。网格的其余部分正常运行。此外,导航抽屉中菜单的每个其他部分项都返回一个片段,该片段正确地附加到操作栏 - 他们甚至没有android:layout_alignParentTop =“true属性 - 除了主屏幕,这是缩略图gridview。代码:
activity_main:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_alignParentTop="true"
android:id="@+id/content_frame"
android:background="#111"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/menu_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#222"/>
main_grid_fragment:
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridView"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="@dimen/image_thumbnail_size"
android:horizontalSpacing="@dimen/image_thumbnail_spacing"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="@dimen/image_thumbnail_spacing" >
grid_main.xml:
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridView"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="@dimen/image_thumbnail_size"
android:horizontalSpacing="@dimen/image_thumbnail_spacing"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="@dimen/image_thumbnail_spacing" >
drawer_items:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:fontFamily=""
android:gravity="center_vertical"
android:paddingLeft="22dp"
android:paddingRight="22dp"
android:textColor="#fff"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall"/>
layout_drawer:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_drawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="#fff"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall"/>