我正在开发一款应用。问题是横向模式中的纵向滚动视图位置相对于纵向模式的变化。我不知道这个。我是android新手。请帮助我。
答案 0 :(得分:2)
在您的活动类中添加此内容。
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
final ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);
outState.putFloatArray("ScrollViewContainerScrollPercentage",
new float[]{
(float) scrollView.getScrollX()/scrollView.getChildAt(0).getWidth(),
(float) scrollView.getScrollY()/scrollView.getChildAt(0).getHeight() });
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
final float[] scrollPercentage = savedInstanceState.getFloatArray("ScrollViewContainerScrollPercentage");
final ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);
scrollView.post(new Runnable() {
public void run() {
scrollView.scrollTo(
Math.round(scrollPercentage[0]*scrollView.getChildAt(0).getWidth()),
Math.round(scrollPercentage[1]*scrollView.getChildAt(0).getHeight()));
}
});
}