問(wèn)題背景:ScrollView中含有l(wèi)istview栖袋,每次啟動(dòng)的時(shí)候?yàn)榱双@取ScrollView的高度,需要完全測(cè)量listview的高度,因此吟榴,在默認(rèn)情況下會(huì)滑動(dòng)到頁(yè)面的最低端,造成問(wèn)題囊扳。
解決方法:
1.(XML)在ScrollView布局中吩翻,找到第一個(gè)View,給它獲取焦點(diǎn)的權(quán)限锥咸,這樣的話狭瞎,在ScrollView測(cè)量完高度的之后,會(huì)相應(yīng)View的獲取權(quán)限的請(qǐng)求搏予,又會(huì)回到View的位置熊锭,解決問(wèn)題。
<View
....
android:focusable="true"
android:focusableInTouchMode="true"
/>
2.(Java)
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.requestFocus();
關(guān)于焦點(diǎn)是什么的問(wèn)題雪侥?
類(lèi)似非觸屏手機(jī)時(shí)代碗殷,需要使用鍵盤(pán)的上下左右去選中某個(gè)應(yīng)用,然后點(diǎn)擊確定執(zhí)行速缨。而觸屏手機(jī)锌妻,我們只需要對(duì)應(yīng)用點(diǎn)擊一次,即可鸟廓,無(wú)需焦點(diǎn)从祝。也就是會(huì)所焦點(diǎn)是為了標(biāo)記你目前選中的位置的。而這個(gè)在日歷中卻是有用的引谜。
android:focusable與android:focusableInTouchMode
前者針對(duì)在鍵盤(pán)下操作的情況牍陌,如果設(shè)置為true,則鍵盤(pán)上下左右選中员咽,焦點(diǎn)會(huì)隨之移動(dòng)毒涧。
而后者,顯然是針對(duì)觸屏情況下的贝室,也就是我們點(diǎn)擊屏幕的上的某個(gè)控件時(shí)契讲,不要立即執(zhí)行相應(yīng)的點(diǎn)擊邏輯仿吞,而是先顯示焦點(diǎn)(即控件被選中),再點(diǎn)擊才執(zhí)行邏輯捡偏。
android:focusable=“true”不會(huì)改變android:focusableInTouchMode唤冈,因此只在鍵盤(pán)狀態(tài)下顯示焦點(diǎn),在TouchMode狀態(tài)下银伟,依舊無(wú)法顯示焦點(diǎn)你虹。
android:focusable=“false”,一定會(huì)使android:focusableInTouchMode=“false”彤避。
android:focusableInTouchMode=“false”,不會(huì)影響android:focusable傅物。
android:focusableInTouchMode=”true”,一定會(huì)是android:focusable=“true”
http://stackoverflow.com/questions/23799064/what-is-the-difference-between-setfocusable-and-setfocusableintouchmode