2017-03-01 12 views
1

ツールバーとグリッドビューで単純なxmlファイルを作成すると、このようなツールバーの下にないツールバーのグリッドビューの情報が表示されます Grid Viewグリッドビューはツールバーの前に表示されません

LinearLayout

と、これは私のxmlファイルである

<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="wrap_content" 
    tools:context="abtech.waiteriano.com.waitrer.MenuActivity"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:minHeight="?attr/actionBarSize" /> 

    <GridView 
     android:id="@+id/menuGridView" 
     android:layout_width="match_parent" 
     android:background="#d2d2d2" 
     android:layout_height="fill_parent" 
     android:layout_margin="4dp" 
     android:columnWidth="80dp" 
     android:gravity="center" 
     android:horizontalSpacing="5dp" 
     android:numColumns="3" 
     android:stretchMode="columnWidth" 
     android:layout_below="@+id/toolbar" /> 
</FrameLayout> 

答えて

2

あなたは

  • はRelativeLayoutのためのあなたでframeLayoutを変更し、私はあなたがのLinearLayout

    使用することをお勧めします 'layout_below'

  • を使うのLinearLayout(垂直方向)のためのあなたでframeLayoutを変更

    diferentオプション

    • を持っています

      例:

      のLinearLayout

      <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="wrap_content" 
          android:orientation="vertical" 
          tools:context="abtech.waiteriano.com.waitrer.MenuActivity"> 
      
          <android.support.v7.widget.Toolbar 
           android:id="@+id/toolbar" 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           android:background="?attr/colorPrimary" 
           android:minHeight="?attr/actionBarSize" /> 
      
          <GridView 
           android:id="@+id/menuGridView" 
           android:layout_width="match_parent" 
           android:background="#d2d2d2" 
           android:layout_height="fill_parent" 
           android:layout_margin="4dp" 
           android:columnWidth="80dp" 
           android:gravity="center" 
           android:horizontalSpacing="5dp" 
           android:numColumns="3" 
           android:stretchMode="columnWidth" /> 
      </LinearLayout> 
      

      RelativeLayout

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
          xmlns:tools="http://schemas.android.com/tools" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          tools:context="abtech.waiteriano.com.waitrer.MenuActivity"> 
      
          <android.support.v7.widget.Toolbar 
           android:id="@+id/toolbar" 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           android:background="?attr/colorPrimary" 
           android:minHeight="?attr/actionBarSize" /> 
      
          <GridView 
           android:id="@+id/menuGridView" 
           android:layout_width="match_parent" 
           android:background="#d2d2d2" 
           android:layout_height="fill_parent" 
           android:layout_margin="4dp" 
           android:columnWidth="80dp" 
           android:gravity="center" 
           android:horizontalSpacing="5dp" 
           android:numColumns="3" 
           android:stretchMode="columnWidth" 
           android:layout_below="@id/toolbar" /> 
      </RelativeLayout> 
      
    1

    変更FrameLayoutと垂直に方向を設定します。

    <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="wrap_content" 
        android:orientation="vertical" 
        tools:context="abtech.waiteriano.com.waitrer.MenuActivity"> 
    
        <android.support.v7.widget.Toolbar 
         android:id="@+id/toolbar" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:background="?attr/colorPrimary" 
         android:minHeight="?attr/actionBarSize" /> 
    
        <GridView 
         android:id="@+id/menuGridView" 
         android:layout_width="match_parent" 
         android:background="#d2d2d2" 
         android:layout_height="fill_parent" 
         android:layout_margin="4dp" 
         android:columnWidth="80dp" 
         android:gravity="center" 
         android:horizontalSpacing="5dp" 
         android:numColumns="3" 
         android:stretchMode="columnWidth" 
         android:layout_below="@+id/toolbar" /> 
    </LinearLayout > 
    
    +1

    それは@Nika Kurdadzeたくさん非常に単純なエラーのおかげです –

    2

    でframeLayoutは、単一のアイテムを表示するように設計されています。

    一般に、単一の子ビューを保持するには、FrameLayoutを使用する必要があります。

    しかし、FrameLayoutに複数の子を追加し、FrameLayout内の位置を制御できます。

    FrameLayoutを続行したい場合は、以下のようにLinearLayoutまたはRelativeLayoutを子としてFrameLayout内に追加できます。おかげOMG

    <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="wrap_content"> 
    
    <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="wrap_content" 
    android:orientation="vertical"> 
    
    <android.support.v7.widget.Toolbar 
        android:id="@+id/toolbar" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="?attr/colorPrimary" 
        android:minHeight="?attr/actionBarSize" /> 
    
    <GridView 
        android:id="@+id/menuGridView" 
        android:layout_width="match_parent" 
        android:background="#d2d2d2" 
        android:layout_height="fill_parent" 
        android:layout_margin="4dp" 
        android:columnWidth="80dp" 
        android:gravity="center" 
        android:horizontalSpacing="5dp" 
        android:numColumns="3" 
        android:stretchMode="columnWidth" 
        android:layout_below="@+id/toolbar" /> 
    

    関連する問題