2016-05-19 40 views
0

我有一個GridView,我通過代碼填充,問題是最後一行不完全可見。我不知道爲什麼發生這種情況時,Activity的佈局很簡單:GridView切斷最後一行

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <GridView 
     android:id="@+id/sectionGrid" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/white" 
     android:horizontalSpacing="0dp" 
     android:numColumns="1" 
     android:stretchMode="columnWidth" 
     android:verticalSpacing="10dp"> 

    </GridView> 
</LinearLayout> 

並且佈局該行如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:pew="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/white" > 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="180dp" 
      android:layout_gravity="center" 
      android:scaleType="centerCrop" 
      android:id="@+id/sectionImage"/> 


     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignTop="@+id/sectionImage" 
      android:layout_alignLeft="@+id/sectionImage" 
      android:layout_alignStart="@+id/sectionImage" 
      android:background="@drawable/bg_section_row" 
      android:layout_alignBottom="@+id/sectionTitle" 
      android:layout_alignRight="@+id/sectionImage" 
      android:layout_alignEnd="@+id/sectionImage" 
      android:id="@+id/sectionBgView"></RelativeLayout> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:textColor="@color/white" 
      android:scrollHorizontally="true" 
      android:ellipsize="end" 
      android:maxLines="1" 
      android:padding="10dp" 
      android:layout_alignBottom="@+id/sectionImage" 
      android:layout_alignLeft="@+id/sectionImage" 
      android:layout_alignStart="@+id/sectionImage" 
      android:layout_alignRight="@+id/sectionImage" 
      android:layout_alignEnd="@+id/sectionImage" 
      android:id="@+id/sectionTitle"/> 


    </RelativeLayout> 
</LinearLayout> 

我不知道,如果它可能是相關的,但目前我使用以下主題:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 

佈局有什麼問題?我是否缺少GridView的任何財產?

+0

在GridView控件集填充....機器人:paddingBottom來= 「20dp」 – sasikumar

+0

@sasikumar我知道,增加填充的作品,但我覺得這是非常hackish的,它不是我想要使​​用的解決方案 – Signo

+0

@Signo您是指當您在'Grid View'中加載動態數據時,它不顯示最後一行? –

回答

0

浪費小時後,我發現在我使用,以創建一個滑動菜單庫這個問題: https://github.com/jfeinstein10/SlidingMenu/issues/680

我已經添加下面的代碼我BaseActivity(每次活動從這個繼承) :

if(Build.VERSION.SDK_INT >= 21) 
      getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); 

它做到了。這個問題似乎只與API的設備發生> 21

+0

這個工程,但切割對我來說,關閉ActionBar, –

1

在GridView的安卓verticalSpacing安卓horizo​​ntalSpacing僅當有另一種細胞給間距的作品。

即使對於間距沒有得到在頂部只要第二小區的繪製屬性verticalSpacing作品,並且可以在小區之間可以觀察到的間隙施加但第一小區。

在這種情況下,底部細胞不具有任何其他單元格以顯示它下面,結果最後一個單元格看起來像是從底部被切斷。

嘗試在行單元格中爲LinearLayout提供填充。
如:的android:paddingBottom來= 「5DP」

相關問題