我在添加到两个文本视图中的 onClickListener 遇到了一些问题,这两个文本视图是我正在开发的应用程序中可访问性栏的一部分。当应用程序在平板电脑上时,侦听器的行为符合预期并适当地增加和减小文本大小,但是当在手机上运行时,无论触摸哪个视图,都只会调用增加大小的侦听器。
如果有人能指出我正确的方向,我将不胜感激,下面是添加两个侦听器的代码。
accLayout = new LinearLayout(this);
accLayout.setOrientation(LinearLayout.HORIZONTAL);
TextView bigger = new TextView(this);
bigger.setBackgroundResource(R.drawable.bigger);
bigger.setLayoutParams(new LayoutParams(screenWidth/5, utils.dpToPx(60)));
bigger.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
htmlLayout.increaseTextSize();
}
});
TextView smaller = new TextView(this);
smaller.setBackgroundResource(R.drawable.smaller);
smaller.setLayoutParams(new LayoutParams(screenWidth/5, utils.dpToPx(60)));
smaller.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
htmlLayout.decreaseTextSize();
}
});
TextView invert = new TextView(this);
invert.setBackgroundResource(R.drawable.invert);
invert.setLayoutParams(new LayoutParams(screenWidth/5, utils.dpToPx(60)));
invert.setHeight(utils.dpToPx(60));
invert.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!HtmlLayout.INVERTED){
htmlLayout.invertColours();
HtmlLayout.INVERTED = true;
} else {
htmlLayout.unInvertColours();
HtmlLayout.INVERTED = false;
}
}
});
LinearLayout sliderContainer = new LinearLayout(this);
sliderContainer.setBackgroundResource(R.drawable.slider);
sliderContainer.setLayoutParams(new LayoutParams((screenWidth/5)*2, utils.dpToPx(60)));
sliderContainer.setGravity(Gravity.CENTER_VERTICAL);
SeekBar brightness = new SeekBar(this);
brightness.setLayoutParams(new LayoutParams((int) (screenWidth * 0.4), utils.dpToPx(30)));
brightness.setMax(100);
brightness.setBackgroundColor(Color.TRANSPARENT);
brightness.setProgress((int) (0.7 * 100));
brightness.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = (float)(progress + 20) / 100.0f;
getWindow().setAttributes(lp);
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
});
sliderContainer.addView(brightness);
accLayout.setGravity(Gravity.CENTER_VERTICAL);
accLayout.addView(bigger);
accLayout.addView(smaller);
accLayout.addView(invert);
accLayout.addView(sliderContainer);
mainContainer.addView(accLayout,2);