问题
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.
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)
回答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
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);
}
来源:https://stackoverflow.com/questions/5246566/android-2-1-how-to-zoom-in-out-and-scroll-on-a-gridview