GridView with incomplete row number does not scroll

I have a problem with mine GridView, when it gets an incomplete line number of a line, it no longer scrolls. My elements are dynamic, which are set by the server, I have 3 columns, and if the number of elements is GridViewmore than enough to include scrolling, and if the row element is 3, it works fine. For example (9 points): complete

But if in the third line there are only 1 or 2 elements / s, it no longer scrolls (7 or 8 elements): incomplete

This caused me a headache more than the excitement of mine GridViewin the layout:

<GridView
    android:id="@+id/gridView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@color/white"
    android:listSelector="@android:color/transparent"
    android:numColumns="3"
    android:stretchMode="columnWidth" >
</GridView>

My activity is nothing special, just the announcement and configuration of its adapter. Did I miss something? I tried to add verticalSpacingand paddingseparately, but nothing has changed.

EDIT: :

whole_layout

Black - RelativeLayout, FrameLayout, ImageView . TextView FrameLayout, TextView TextView. GridView TextView ImageView, , . .

, , , ListView, .

EDIT2: :

<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="match_parent"
    android:orientation="vertical"
    tools:context=".SixthActivity" >

    <FrameLayout
        android:id="@+id/cover_frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/cover_image"
                android:layout_width="match_parent"
                android:layout_height="180dp"
                android:background="@color/gray"
                android:scaleType="centerCrop" />

            <ProgressBar
                android:id="@+id/cover_image_progressbar"
                style="?android:attr/progressBarStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="180dp" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:layout_alignParentBottom="true"
                android:orientation="horizontal" >

                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="center_vertical"
                    android:layout_margin="10dp" />

                <TextView
                    android:id="@+id/school_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="10dp"
                    android:layout_marginTop="10dp"
                    android:ellipsize="end"
                    android:maxLines="2"
                    android:textColor="@color/white"
                    android:textStyle="bold" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/container_sns"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_margin="10dp"
                android:gravity="right"
                android:orientation="horizontal" >

                <ImageView
                    android:id="@+id/btn_telephone"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:visibility="gone" />

                <ImageView
                    android:id="@+id/btn_email"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:visibility="gone" />

                <ImageView
                    android:id="@+id/btn_facebook"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:visibility="gone" />

                <ImageView
                    android:id="@+id/btn_twitter"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:visibility="gone" />

                <ImageView
                    android:id="@+id/btn_line"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:visibility="gone" />
            </LinearLayout>
        </RelativeLayout>
    </FrameLayout>

    <TextView
        android:id="@+id/student_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/cover_frame"
        android:background="#f8f7f3"
        android:padding="10dp"
        android:textColor="@color/brown"
        android:textStyle="bold" />

    <RelativeLayout
        android:id="@+id/container_news"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/student_name"
        android:background="@drawable/bg_news"
        android:clickable="true"
        android:orientation="horizontal"
        android:visibility="gone" >

        <TextView
            android:id="@+id/news"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="85dp"
            android:layout_marginRight="10dp"
            android:clickable="true"
            android:ellipsize="end"
            android:maxLines="2"
            android:textColor="@color/brown"
            android:textStyle="bold" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/container_next_plan"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/container_news"
        android:background="@drawable/bg_next"
        android:clickable="true"
        android:orientation="horizontal"
        android:visibility="gone" >

        <TextView
            android:id="@+id/next_plan"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="85dp"
            android:layout_marginRight="10dp"
            android:clickable="true"
            android:ellipsize="end"
            android:maxLines="2"
            android:textColor="@color/brown"
            android:textStyle="bold" />
    </RelativeLayout>

    <GridView
        android:id="@+id/grid_view"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/mypage_footer"
        android:layout_below="@id/container_next_plan"
        android:background="#ACA899"
        android:gravity="center"
        android:numColumns="3" >
    </GridView>

    <ImageView
        android:id="@+id/mypage_footer"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:scaleType="fitXY" />

</RelativeLayout>

ImageView s, . . :

public class SixthActivity extends Activity {

    private Integer[] gridViewItem = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sixth);

        GridView gridView = (GridView) findViewById(R.id.grid_view);
        CustomAdapter adapter = new CustomAdapter(this,
                R.layout.item_module, gridViewItem);

        gridView.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.sixth, menu);
        return true;
    }

}

:

public class CustomAdapter extends ArrayAdapter<Integer> {

    private Context context;
    private int resource;
    private Integer[] moduleList;

    public CustomAdapter(Context context, int resource,
            Integer[] moduleList) {
        super(context, resource, moduleList);
        // TODO Auto-generated constructor stub
        this.context = context;
        this.resource = resource;
        this.moduleList = moduleList;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ViewHolder holder = null;

        if (row == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            row = inflater.inflate(resource, parent, false);
            holder = new ViewHolder();
            row.setTag(holder);
        } else {
            holder = (ViewHolder) row.getTag();
        }

        holder.tvModuleName = (TextView) row.findViewById(R.id.module_name);
        holder.tvModuleImage = (ImageView) row.findViewById(R.id.module_image);

        holder.tvModuleName.setText("SAMPLESAMPLE");
        return row;
    }

    public class ViewHolder {
        public ImageView tvModuleImage;
        public TextView tvModuleName;
    }
}

:

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

    <ImageView
        android:id="@+id/module_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/module_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:ellipsize="end"
        android:singleLine="true" />

</LinearLayout>

gridViewItem, , , , 1 2 , . .

+4

Source: https://habr.com/ru/post/1526511/


All Articles