无法在ScrollView中正确对齐按钮
问题描述:
我在任何地方都看到了这个问题,但我认为每个案例都有自己的解决方案。我所拥有的是这样的:无法在ScrollView中正确对齐按钮
<HorizontalScrollView
android:id="@+id/MenuScroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="48dp"
android:orientation="horizontal"
android:layout_gravity="center"
android:padding="0dp" >
<Button
android:layout_width="150dp"
android:layout_height="fill_parent" />
<Button
android:layout_width="150dp"
android:layout_height="fill_parent" />
<Button
android:layout_width="150dp"
android:layout_height="fill_parent" />
<Button
android:layout_width="150dp"
android:layout_height="fill_parent" />
<Button
android:layout_width="150dp"
android:layout_height="fill_parent" />
</LinearLayout>
</HorizontalScrollView>
什么,我假装是具有中心的HorizontalScrollView
内LinearLayout
。它居中(我看到半按钮 - 半键)但我不能滚动到第一个按钮。看起来左侧隐藏的内容占用的空间被添加到右侧,并且在HorizontalScrollView
之后添加了一些空间。
有没有解决方案,即使我必须动态地执行它?
答
我有同样的问题,以避免它只是从
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="48dp"
android:orientation="horizontal"
android:layout_gravity="center"
android:padding="0dp" >
删除
android:layout_gravity="center"
您可以在创建布局视图,以正常滚动添加一个计时器。如果您不添加计时器,则由于未创建视图而不会滚动。你不能滚动的东西,它不能被看到
new Timer().schedule(new TimerTask() {
@Override
public void run() {
//SOME SCROLLING FUNCTION
}}, 50);
它确实但按钮没有居中'HorizontalScrollView'里面了。以我为中心,我的意思是3左边和3右边。我会尝试ScrollTo,但它不会。 – ali 2013-03-05 08:56:13
当您尝试在视图创建之前滚动时,ScrollTo通常会遇到问题。尝试添加计时器任务,我将其添加到解决方案中 – Dante 2013-03-05 12:56:41