Android 2.1的:如何放大/缩小和滚动一个GridViewAndroid、GridView

2023-09-05 04:35:50 作者:不知

背景: 我的工作程序包含有5行11列有一个重写的适配器,用于显示一个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 porting to a small scale smartphone, I realize that the grid is unusable, due to its small size. Rather than implement landscape orientation I've decided to use a zoom function.

问: 什么是实现以下两个基本功能的最佳方式:变焦(允许放大100至400%)和Scroll(上/下/左/右)

QUESTION: What is the best way to implement the following 2 basic functions: Zoom (allow zoom between 100 and 400%) and Scroll (up/down/right/left)

推荐答案

我的解决方案是创建一个布局重新计算程序,改变列#及其大小

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);
  }