1. android Popupwindow 遇到軟鍵盤時,出現位置發生上移
在AndroidManifest中添加
<activity android:name="testActivity"
android:windowSoftInputMode="adjustPan">
設置屬性為android:windowSoftInputMode="adjustResize"即可自動調整高度。
屬性stateVisible表示默認顯示輸入法鍵盤,其他屬性見:android:windowSoftInputMode
2. 如何在android程序執行初始化的時候彈出一個PopupWindow 觸發的事件是在初始化的時候。
new一個Handler變數,在OnCreate裡面通過這個Handler去發送消息,handler在Onmessage裡面收到消息後,在show出來就可以了;類似的情況還有在oncreate裡面不能顯示toast之類的,要用線程去處理
3. 安卓popupwindow怎麼預先載入
ublic static View showPopupWindowMenu(Activity mContext, View anchorView, int layoutId) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(layoutId, null);
popupWindow = new PopupWindow(view, DisplayUtil.dip2px(mContext, 148), WindowManager.LayoutParams.WRAP_CONTENT);
popupWindow.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.menu_bg));
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
4. 安卓中使用的popupwindow設置默認選擇哪個條目
Android PopupWindow怎麼合理控制彈出位置
privatevoidshowPopupWindow(Viewparent){
if(popupWindow==null){
LayoutInflaterlayoutInflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view=layoutInflater.inflate(R.layout.group_list,null);
lv_group=(ListView)view.findViewById(R.id.lvGroup);
Collections.reverse(groups);
GroupAdaptergroupAdapter=newGroupAdapter(this,groups);
lv_group.setAdapter(groupAdapter);
popupWindow=newPopupWindow(view,200,220);
}
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);//設置點擊屏幕其它地方彈出框消失
popupWindow.setBackgroundDrawable(newBitmapDrawable());
WindowManagerwindowManager=(WindowManager)getSystemService(Context.WINDOW_SERVICE);
intxPos=-popupWindow.getWidth()/2
+getCustomTitle().getCenter().getWidth()/2;
popupWindow.showAsDropDown(parent,xPos,4);
lv_group.setOnItemClickListener(newOnItemClickListener(){
@Override
publicvoidonItemClick(AdapterView<?>adapterView,Viewview,
intposition,longid){
loadNew(((StringItem)(groups.get(position))).getId());
if(popupWindow!=null)
popupWindow.dismiss();
}
});
}
5. 安卓popupwindow 內多列listview寬度怎麼適應
1、布局的不同,有太大區別的布局肯定是區分多類的,當然這也是夠累的;
2、字體使用SP單位自適應,圖片採取.9圖片拉伸;
3、布局使用相對布局
4、一般人不想用的權重屬性,layout_weight,
5、控制項長寬控制使用dip單位;
舉例
Popupwindow這樣創建的:new PopupWindow(maplistview,LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
ListView中的item是一個LinearLayout,水平排列,一個Checkbox,一個Button。所有設置都是WRAP_CONTENT。但是效果卻是,ListView在手機和平板上都沒有自適應,手機上偏擠(Button裡面總共兩個字,上下排列了),平板上Button里的兩個字水平排列,而且Button後面還有很大一段的空間。
答:
手機上偏擠,是因為字體大了,控制項的空間小了;
平板上可以水平顯示,但字的顯示不是很理解,是因為沒有設置字的顯示位置,
建議:
進行相應的更改,如,改變字體大小,或者改變控制項的長寬,
平板的話,可以先設置字體的位置,如gravity的使用;
6. 安卓中popwindow怎麼在activity中生命周期中直接啟動
getActivity()方法獲得Activity,然後就可以使用其startActivity等了。 PopupWindow是一種不完全覆蓋父窗口的View,通常一些快捷方式,使用它最合適了。
7. 使彈出popupwindow界面外部的控制項不能點擊
我記得popupwindow本來就不可點擊被覆蓋的界面。如果不行,可以設置一個全屏的activity,這個activity設置為透明,把popupwindow顯示到這個透明的activity上。
8. 安卓開發popupwindow
PopupWindow 跟我們的 Activity 不一樣,因為我們在構造 PW 的時候往往不是繼承來的,而是 new 出來的。
所以不能使用重寫 PW 的 onKeyDown() 之類的方法來截獲鍵盤事件。
好在 PW 本身的特性讓我們很容易就能做到用返回鍵來退出,當然我們也可以截獲鍵盤事件,這樣就有兩種方法了。
最簡單——
在 new 的時候,使用下面的方法:
new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
關鍵在於最後一個參數,ADK 給出的提示是 Focusable,顧名思義就是該 PW 的 Focusable 屬性,讓它能夠接受焦點。
當然你也可以手動設置它:
1
2
PW.setFocusable(true);
PW.setFocusableInTouchMode(true); //為了保險起見加上這句
此時實際上還是不能起作用的,網路給出的結論是,必須加入下面這行作用未知的語句才能發揮作用:
pw.setBackgroundDrawable(new BitmapDrawable()); // www.linuxidc.com響應返回鍵必須的語句
請放心,設置 BackgroundDrawable 並不會改變你在配置文件中設置的背景顏色或圖像。
最通用——
首先在 PW 的布局文件(*.xml)中隨意選取一個不影響任何操作的 View,推薦使用最外層的 Layout。
然後設置該 Layout 的 Focusable 和 FocusableInTouchMode 都為 true。
接著回到代碼中,獲取該 View 的實例,現在你就可以對該 View 重寫 OnKeyListener() 事件了。
我們可以手動捕獲 KEYCODE_BACK 給對話框 dismiss()。
給出一段示例:
private PopupWindow pw;
private View view;
private LinearLayout layMenu;
LayoutInflater inflater = (LayoutInflater) main.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.popup_main_menu, null, false);
layMenu = (LinearLayout) view.findViewById(R.id.layMenu);
pw = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
layMenu.setOnKeyListener(new OnKeyListener()
{
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK)
pw.dismiss();
return false;
}
});
上面兩種方法的代碼可以並存,當然如果使用第一種方法的話就不需要再捕獲返回鍵了,不過你可以嘗試捕獲其他你需要的按鍵
1. 若需要監聽PopUpWindow里控制項的事件,如PopUpWindow裡面一個按鈕的事件,那麼就需要調用方法setFocusable(true)獲得焦點,並且在調用setFocusable(true)方法後,可以通過Back(返回)菜單使PopUpWindow dimiss;另外調用方法setOutsideTouchable(true)後,點擊PopUpWindow外面的控制項也可以使得PopUpWindow dimiss。需要順利讓PopUpWindow dimiss;PopUpWindow的背景不能為空。
2. 如圖:輸入框EditText下面為PopUpWindow
3.設置代碼如下
PopupWindow popUpWin;
popUpWin=new PopupWindow(listView,edtUserName.getWidth(),LayoutParams.WRAP_CONTENT);
//必須設置背景
popUpWin.setBackgroundDrawable(new BitmapDrawable());
//設置焦點
popUpWin.setFocusable(true);
//設置點擊其他地方 就消失
popUpWin.setOutsideTouchable(true);
popUpWin.showAsDropDown(edtUserName);
<!--EndFragment-->
更多編程開發上的其他問題
你來我們群里說吧
這里是開發者互相學習交流的
有大神
讓他們給你解釋你的疑問 q un號: 18816 8040
9. 安卓編程:menu鍵呼出popupwindow,但是點擊actionbar中的圖標可以顯示右上角的
找找actionbar的介面,應該可以攔截左上角的事件,或者就不用actionbar做。