问题描述
我有一个通过代码填充的 GridView
,问题是它的最后一行不完全可见.我不知道为什么会这样, Activity
的布局非常简单:
I have a GridView
that I populate through code, the problem is that the last row it's not fully visible. I don't know why this is happening, the layout of the Activity
is pretty simple:
<?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>
我不确定是否可能与之相关,但目前我正在使用以下主题:
I'm not sure if it might be related but currently i'm using the following theme:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
布局有什么问题?我是否缺少 GridView
的任何属性?
What's wrong with the layout? am I missing any property for the GridView
?
推荐答案
浪费时间后,我在我正在使用的库中发现了此问题,以便创建滑动菜单": https://github.com/jfeinstein10/SlidingMenu/issues/680
after wasting hours I found out this issue on the library i'm using in order to create a Sliding Menu:https://github.com/jfeinstein10/SlidingMenu/issues/680
我已经在我的BaseActivity中添加了以下代码(每个活动都继承自此):
I've added the following code to my BaseActivity (every activity inherits from this):
if(Build.VERSION.SDK_INT >= 21)
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
它成功了.该问题似乎仅在具有API> 21
And it did the trick. The problem seem to happen only on devices with API > 21
这篇关于GridView切断最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!