有人能告诉我在网格视图中实现水平滚动的方法吗?
答案 0 :(得分:4)
最后我能够在android中实现水平滚动网格视图......这是代码:
public class HorizontalGridView extends Activity {
Bitmap viewBgrnd;
ImageButton img ;
Button button;
Button b1[] = new Button[100];
static int total=0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
horizontalScrollGalleryLayout();
}
public void horizontalScrollGalleryLayout () {
Integer[] mThumbIds = {
R.drawable.image0,R.drawable.image1,R.drawable.image2,
R.drawable.image3,R.drawable.image4,R.drawable.image5,
R.drawable.image6,R.drawable.image7,R.drawable.image8,
R.drawable.image9,R.drawable.image10,R.drawable.image11,
R.drawable.image12,R.drawable.image13,R.drawable.image14,
R.drawable.image15,R.drawable.image16,R.drawable.image17,
R.drawable.image18,R.drawable.image19,R.drawable.image20,
R.drawable.image21,R.drawable.image22,R.drawable.image23,
R.drawable.image24,R.drawable.image25,R.drawable.image26,
R.drawable.image27,R.drawable.image28,R.drawable.image29,
R.drawable.image30,R.drawable.image31,R.drawable.image32,
R.drawable.image33,R.drawable.image34,R.drawable.image35,
R.drawable.image36,R.drawable.image37,R.drawable.image38,
R.drawable.image39,R.drawable.image40,R.drawable.image41,
R.drawable.image42,R.drawable.image43,R.drawable.image44,
R.drawable.image45,R.drawable.image46,R.drawable.image47,
R.drawable.image48,R.drawable.image49,R.drawable.image50,
R.drawable.image51,R.drawable.image52,R.drawable.image53,
R.drawable.image54,R.drawable.image55,R.drawable.image56,
R.drawable.image57,R.drawable.image58,R.drawable.image59,
R.drawable.image60,R.drawable.image61,R.drawable.image62,
R.drawable.image63,R.drawable.image64,R.drawable.image65,
R.drawable.image66,R.drawable.image67,R.drawable.image68,
R.drawable.image69,R.drawable.image70,R.drawable.image71,
R.drawable.image72,R.drawable.image73,R.drawable.image74,
R.drawable.image75,R.drawable.image76,R.drawable.image77,
R.drawable.image77,R.drawable.image79,R.drawable.image8,
R.drawable.image81,R.drawable.image82,R.drawable.image83,
R.drawable.image84,R.drawable.image85,R.drawable.image86,
R.drawable.image87,R.drawable.image88,R.drawable.image89,
R.drawable.image90,R.drawable.image91,R.drawable.image92,
R.drawable.image93,R.drawable.image94,R.drawable.image95,
R.drawable.image96,R.drawable.image97,R.drawable.image98,
R.drawable.image99,
};
HorizontalScrollView sv = new HorizontalScrollView(this);
LinearLayout llh = new LinearLayout(this);
llh.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams layoutParamsTV = new LinearLayout.LayoutParams(100,100);
LinearLayout.LayoutParams layoutParamsLL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams layoutParamsLLD = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
for(int k=0;k<mThumbIds.length;k++)
{
LinearLayout llv = new LinearLayout(this);
for (int i=0; i<4; i++) {
llv.setOrientation(LinearLayout.VERTICAL);
button = new Button(this);
try {
button.setBackgroundResource(mThumbIds[total]);
total++;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
llv.addView(button, layoutParamsTV);
//b1[k].setBackgroundResource(mThumbIds[k]);
}
//llv.addView(button, layoutParamsTV);
llh.addView(llv, layoutParamsLL);
llh.setBackgroundColor(Color.GRAY);
}
sv.addView(llh, layoutParamsLLD);
setContentView(sv);
sv.setBackgroundColor(Color.GRAY);
}
}
答案 1 :(得分:-1)
答案 2 :(得分:-1)
网格视图问题中的水平滚动条在此通过另一种方式解决。在水平滚动视图中的每个网格视图中都使用了按钮。