get GridView Column Number by orientation - Android User Interface

Android examples for User Interface:GridView

Description

get GridView Column Number by orientation

Demo Code


//package com.java2s;
import android.app.Activity;
import android.content.res.Configuration;

public class Main {
    private static int PORTRAIT_GRIDVIEW_COLUMN_NUMBER = 2;
    private static int LANDSCAPE_GRIDVIEW_COLUMN_NUMBER = 4;

    public static int getColumnNumber(Activity activity) {
        int colNum = PORTRAIT_GRIDVIEW_COLUMN_NUMBER;
        boolean isLand = isScreenOrientationLandscape(activity);
        if (isLand)
            colNum = LANDSCAPE_GRIDVIEW_COLUMN_NUMBER;

        return colNum;
    }/*from   ww  w .  j  a  v  a2 s.  c  o m*/

    private static boolean isScreenOrientationLandscape(Activity activity) {
        Configuration conf = activity.getResources().getConfiguration();
        if (conf.orientation == Configuration.ORIENTATION_LANDSCAPE)
            return true;

        return false;
    }
}

Related Tutorials