Android 2.1: How to zoom in/out and scroll on a GridView

前端 未结 1 1467
星月不相逢
星月不相逢 2021-01-23 14:49

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 displ

相关标签:
1条回答
  • 2021-01-23 15:42

    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

    public void gvlpRecalc() {
        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) {
            case 8:
              btnHeight = (int) (btnWidth * .9);
              break;
            case 10:
              btnHeight = (int) (btnWidth * 1.2);
              break;
            default:
              btnHeight = btnWidth;
          }
        } else
          switch (m_Columns) {
            case 8:
              btnHeight = (int) (btnWidth * .9);
              break;
            case 10:
              btnHeight = (int) (btnWidth * 1.2);
              break;
            case 11:
              btnHeight = btnWidth;
              break;
            default:
              btnHeight = (int) (m_gv.getHeight() / 2.2);
          }
        gvlp = new GridView.LayoutParams(btnWidth, btnHeight);
      }
    
    0 讨论(0)
提交回复
热议问题