将GridView的ScrollBar绑定到屏幕的末尾

时间:2015-04-11 09:08:25

标签: android gridview

如何更改ScrollBarGridView的位置?

它与我案件中的物品位置绑定:

enter image description here

以及最后一个项目与ScrollBar之间的可用空间。这个滚动与项目重叠。我需要保存paddingRight项目,但不保存ScrollBar

我该怎么做?

gridview .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="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="tenkol.design.com.imbrecords.FragmentChannelsUkr"
    android:background="@color/white">

    <GridView android:id="@+id/gridView_ua"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="3"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:stretchMode="columnWidth"
        android:drawSelectorOnTop="true"
        android:gravity="center" />

</FrameLayout >

gridview item .xml

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

    <tenkol.design.com.imbrecords.SquaredImageView
        android:id="@+id/imageview_channelIcon"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="1dp"
        android:scaleType="center"
        />
</RelativeLayout>

修改


当前(请参阅ScrollBar与图像重叠):

enter image description here

预期:

enter image description here

1 个答案:

答案 0 :(得分:0)

自己解决:

删除布局中的填充,以便gridview全屏显示:

<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="tenkol.design.com.imbrecords.FragmentChannelsUkr"
android:background="@color/white">

<GridView android:id="@+id/gridView_ua"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:numColumns="3"
    android:stretchMode="columnWidth"
    android:drawSelectorOnTop="true"
    android:gravity="center" />
</FrameLayout >

并向我的SquaredImageView添加了填充:

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
    setPadding(16,16,16,16);//Snap to width
}