Nik*_*ddy 4 android horizontalscrollview android-tabhost
我正在开发一个TabHost包含的示例应用程序HorizontalScrollView.这是我的问题:
提前致谢!!!
这将涉及一些计算.
实际上,您需要滚动到位置以使元素居中.
int scrollX = (button.getLeft() - (screenWidth/2))+(button.getWidth()/2);
hScrollView.scrollTo(scrollX,0);
Run Code Online (Sandbox Code Playgroud)
在哪里
button -> It is the button you are trying to center.
screenWidth -> Width of the screen.
int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
hScrollView -> It is the horizontal scrollview.
Run Code Online (Sandbox Code Playgroud)
但即使使用此方法,您也无法将末尾元素居中,因为scrollview不会滚动超出其边界.
| 归档时间: |
|
| 查看次数: |
3799 次 |
| 最近记录: |