【发布时间】:2012-03-12 17:57:41
【问题描述】:
我在管理水平滚动视图时遇到了很大的问题。它有一个水平线性布局,有很多垂直线性布局,有一个文本和一个图像。
我希望当用户按下垂直线性布局时,必须调用 ontouchlistener 来启动我的应用程序的新功能。
问题是当用户滚动滚动视图时,verticallinearlayouts 的 ontouchlistener 被调用,我不希望这样。
如何解决?
谢谢
我的代码:
final HorizontalScrollView hsv = new HorizontalScrollView(this);
RelativeLayout.LayoutParams hsvParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
hsvParams.addRule(RelativeLayout.BELOW,6);
hsv.setBackgroundColor(0x55383838);
hsv.setLayoutParams(hsvParams);
hsv.setVisibility(View.GONE); //inicialmente está oculto
LinearLayout hsvll = new LinearLayout(this);
hsvll.setOrientation(LinearLayout.HORIZONTAL);
hsvll.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
hsvll.setPadding(0, 0, 0, 5);
createThumbnails();
List <LinearLayout> thumbnailLinearLayouts = new ArrayList<LinearLayout>();
for (int i=1; i<=squareGLSurfaceView.pages.size();i++){ //el tope es <=pages.size() porque hay que recordar que se ha añadido una página en blanco al principio, por lo que la última página será = .size(). Nos guiamos por pages.size en lugar de thumbnails.size() porque thumbnails.size() puede haber crecido para añadir una página en blanco al final, que no queremos mostrar
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
ll.setPadding(10, 0, 10, 0);
thumbnailLinearLayouts.add(ll);
TextView tv = new TextView(this);
tv.setText(""+(i));
tv.setGravity(Gravity.RIGHT);
ll.addView(tv);
ImageView iv = new ImageView(this);
iv.setImageBitmap(thumbnails.get(i));
ll.addView(iv);
hsvll.addView(ll);
}
hsv.addView(hsvll);
rl.addView(hsv);
for (int i=0;i<thumbnailLinearLayouts.size();i++){
final int auxIndex=i;
thumbnailLinearLayouts.get(i).setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
MagazineStatus.currentPage=auxIndex;
hsv.setVisibility(View.GONE);
return true; }
});
}
【问题讨论】:
标签: android android-layout scrollview ontouchlistener