【发布时间】:2014-11-06 00:51:40
【问题描述】:
我无法让 HorizontalScrollView 滚动到某个 X 位置或 X 像素。它有一个线性布局,里面有按钮。
<HorizontalScrollView
android:id="@+id/horizontal_room_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0dp"
android:scrollbars="none">
<LinearLayout
android:orientation="horizontal"
android:id="@+id/roomsBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- buttons -->
</LinearLayout>
</HorizontalScrollView>
Java:
buttonList = (HorizontalScrollView) findViewById(R.id.horizontal_room_list);
//do stuff, at some point successfully save the scrolling offset with getScrollX()
barOffsetX = buttonList.getScrollX();
Log.e("x", "" + barOffsetX); //this prints a correct > 0 value
buttonList.scrollBy(barOffsetX, 0); //nothing happens, or
buttonList.scrollTo(barOffsetX, 0); //nothing happens
我认为问题可能与 LinearLayout 有关。如何让它滚动?
编辑:我认为问题在于以编程方式添加新按钮。
【问题讨论】:
标签: android xml android-linearlayout horizontal-scrolling horizontalscrollview