我在linearlayout中有一个视图和一个textview。 LinearLayout存在于ScrollView中。我希望滚动视图向下移动,单击该屏幕中的按钮,再次向上移动再次单击
答案 0 :(得分:1)
试试这个 -
private ImageView list_scroll_iv;
private int focus_pos=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list_scroll_iv = (ImageView)findViewById(R.id.list_scroll_iv);
list_scroll_iv.setOnClickListener(this);
}
@Override
public void onClick(View v) {
list_sv.post(new Runnable() {
@Override
public void run() {
//1 for up and 2 for down
if(focus_pos==1) {
list_sv.fullScroll(ScrollView.FOCUS_DOWN);
focus_pos=2;
list_scroll_iv.setImageDrawable(getResources().getDrawable(R.drawable.blue_arrow_ic_up));
}
else {
list_sv.fullScroll(ScrollView.FOCUS_UP);
focus_pos=1;
list_scroll_iv.setImageDrawable(getResources().getDrawable(R.drawable.blue_arrow_ic_down));
}
}
});
}
答案 1 :(得分:0)
要向下滚动按钮,请使用此按钮:
scrollView.post(new Runnable()
{
@Override
public void run()
{
//X,Y are scroll positions untill where you want scroll down
scrollView.scrollTo(X, Y);
}
});
要向上滚动按钮,请使用此按钮:
scrollView.post(new Runnable()
{
@Override
public void run()
{
//X,Y are scroll positions untill where you want scroll up
int X=0,Y=0;
scrollView.scrollTo(X, Y);
}
});