我膨脹另一個佈局,使其出現在我當前佈局的某個視圖下方。scrollTo()for horizontalScrollView不起作用
這是這樣完成的:
LayoutInflater vi = (LayoutInflater) getActivity().getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rootView = vi.inflate(R.layout.horizontal_scroll_view, null);
horizontalScrollView = (HorizontalScrollView) rootView.findViewById(R.id.hsv_suggestions_scroll_view);
LinearLayout suggestionsContainer = (LinearLayout) horizontalScrollView.findViewById(R.id.ll_suggestions_container);
,我可以證實它,因爲我一段時間後在其中加入一些看法,他們都出現出現在正確的地方。
我膨脹的佈局是:
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/hsv_suggestions_scroll_view"
android:scrollbars="none" android:layout_gravity="center_horizontal"
android:paddingTop="16dp" android:fillViewport="true"
android:layout_width="match_parent" android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/ll_suggestions_container"
android:gravity="center_horizontal" android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</LinearLayout>
只是一個帶有LinearLayout
作爲一個孩子HorizontalScrollView
。 我後來添加的視圖都是TextView
s。
現在,在用戶操作(在editText上編寫一些文本)後,我正在嘗試滾動到該視圖並將其突出顯示。突出作品。不起作用的是滾動。
我曾嘗試:
horizontalScrollView.postDelayed(new Runnable() {
@Override
public void run() {
horizontalScrollView.smoothScrollTo(scrollTo, 0);
}
}, 300);
其中變量scrollTo
是我所得到的,當我申請getLeft()
到視圖我想滾動到。我可以證實它具有各種價值。
任何人都可以幫助我嗎?
我只是把這種情況扔在一起,它對我來說工作得很好。你有沒有嘗試在你的'smoothScrollTo()'中放入一個隨機數來查看它會滾動任何東西? – LukeWaggoner
@idratherbeintheair是我試着添加一些隨機數字,但沒有幫助 – Mes
因此,它使用隨機數字時不滾動? – LukeWaggoner