Skip to content Skip to sidebar Skip to footer

Android 2.1: How To Zoom In/out And Scroll On A Gridview

BACKGROUND: My working app contains a GridView with 5 rows of 11 columns with an overridden adapter for display. It works great for my needs with a large display tablet. After p

Solution 1:

My solution was to create a layout recalculation routine, changing the # of columns and their sizes

There may be a better way, but with no replies, this is a quick and dirty hack that worked

publicvoidgvlpRecalc() {
    m_gv.setNumColumns(m_Columns);
    if ((btnWidth = (int) (m_gv.getWidth() / m_Columns + .5)) == 0) {
      Display display = ((Activity) m_Context).getWindowManager().getDefaultDisplay();
      btnWidth = (int) (display.getWidth() / m_Columns + .5);
      switch (m_Columns) {
        case8:
          btnHeight = (int) (btnWidth * .9);
          break;
        case10:
          btnHeight = (int) (btnWidth * 1.2);
          break;
        default:
          btnHeight = btnWidth;
      }
    } elseswitch (m_Columns) {
        case8:
          btnHeight = (int) (btnWidth * .9);
          break;
        case10:
          btnHeight = (int) (btnWidth * 1.2);
          break;
        case11:
          btnHeight = btnWidth;
          break;
        default:
          btnHeight = (int) (m_gv.getHeight() / 2.2);
      }
    gvlp = new GridView.LayoutParams(btnWidth, btnHeight);
  }

Post a Comment for "Android 2.1: How To Zoom In/out And Scroll On A Gridview"