我有一個HorizontalScrollView
包含LinearLayout
,其中又包含一對FrameLayout
s。每個FrameLayout
包含Fragment
的佈局。現在我試圖獲得視圖,即FrameLayout
,該視圖當前可見或焦點在HorizontalScrollView
之內。只要我把焦點放在視圖上,我可以得到它在LinearLayout
之內的索引。Android - HorizontalScrollView - 獲取焦點(或索引)
我試過以下,但沒有任何工程:
- HorizontalScrollView.findFocus() - 返回null
- LinearLayout.findFocus() - 返回null
- LinearLayout.getFocusedChild() - 返回空
- FrameLayout.hasFocus() - 返回所有
FrameLayout
小號
我可以假通過根據每個孩子的當前X位置進行計算,試圖找出LinearLayout
中哪個孩子有焦點。但是,每個孩子撥打getX()
總是返回「0.0」。
有沒有人有一個想法如何獲得焦點(或甚至更好它的指數內的LinearLayout
)?
你不介意與我們分享您爲什麼會想要做這樣的事情?我只是好奇。 – 2012-04-15 18:07:17
我需要跟蹤哪些片段是可見的用於日誌目的 – Schnodahipfe 2012-04-15 19:01:29