我有一个' HorizontalScrollView'的子类。其中有可变大小的图像。我想在HorizontalScrollView下面左右两个按钮显示。单击左键时,horizontalscollView应向左滚动左侧第一个不可见图像的大小,现在此图像可见,右键也相同。如果在那一侧到达列表的末尾,我也希望相应的按钮消失。
有人可以帮我这么做吗
答案 0 :(得分:0)
正确执行侦听器,如下所示: 此方法获取图像ID数组并滚动到数据中提供的数据 适当使用getLeft和getRight
/**
* handles button presses that requiere extra data to be passed along
* for dynamic created buttons
* in this app it uses mainly for the navigation bar buttons
* @author new
*
*/
public class ButtonHandler implements OnClickListener,Runnable
{
private int_data;//current left or right location
private ArrayList<Integer> _resultId;//the id's of the imagess
private Activity _activity;
public ButtonHandler(String data,ArrayList<Integer> resultId,Activity activity)
{
_data=data;
_resultId=resultId;
_activity=activity;
}
@Override
public void run()
{
View currentView=_activity.findViewById(_resultId.get(_data));
ScrollView scrollView=(ScrollView) _activity.findViewById(R.id.resultScroll);
scrollView.scrollTo(0, currentView.getLeft());
//get new image for nextClick
Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
for (Int i:_resultId)
{
if (_resultId.getLocalVisibleRect(scrollBounds))
{// Any portion of the imageView, even a single pixel, is within the visible window
data=i;
}
}
}
@Override
public void onClick(View v)
{
new Handler().post(this);
}
}