2016-12-01 17 views
0

Listが読み込まれるにつれて大きくなるPopupWindowにListViewの内容を表示しようとしています。それは、要素が新しい要素の追加を停止するまで、リストが大きくなるにつれてシフトする点を除いて、うまく動作します。スクリーン上で下向きになるとウィンドウの位置を固定したままにする方法はありますか?私はAndroidプログラミングには新しいので、どんな入力も感謝しています。ありがとう!PopupWindowが子のときにシフトするListViewが大きくなる

private void initView(View v) { 

    LayoutInflater inflater = (LayoutInflater) 
    getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    View popupView = inflater.inflate(R.layout.popup_layout, null); 

    DisplayMetrics displaymetrics = new DisplayMetrics(); 

    getActivity().getWindowManager().getDefaultDisplay(). 
    getMetrics(displaymetrics); 

    int width = (int) ((int)displaymetrics.widthPixels * 0.9); 

    popupWindow = new PopupWindow(popupView,width, 
         ViewGroup.LayoutParams.WRAP_CONTENT); 

    m = (MainActivity) getActivity(); 

    m.layout_main.getForeground().setAlpha(220); 

    btnScan = (Button) popupView.findViewById(R.id.scan); 

    btncancel = (Button) popupView.findViewById(R.id.close); 

    popupWindow.setOutsideTouchable(false); 

    popupWindow.setFocusable(true); 


    int loc_int[] = new int[2]; 
    if (v == null) 

    try 
    { 
     v.getLocationOnScreen(loc_int); 
    } catch (NullPointerException npe) 
    { 
     //when the view doesn't exist on screen anymore. 

    } 

    Rect location = new Rect(); 
    location.left = loc_int[0]; 
    location.top = loc_int[1] ; 
    location.right = location.left + v.getWidth()/2; 
    location.bottom = location.top - view2.getHeight()/2 ; 


    popupWindow.showAtLocation(view2, Gravity.CENTER, 
           view2.getWidth()/2, location.top); 

    popupWindow.showAsDropDown(view2); 

    listDevicesFound = (ListView) popupView.findViewById(R.id.devicelist); 

    btAdapter = BluetoothAdapter.getDefaultAdapter(); 

    adtDevice = new ArrayAdapter<String>(getActivity(),R.layout.list_text, 
       lsDevice);   

    listDevicesFound.setAdapter(adtDevice); 

    listDevicesFound.setOnItemClickListener(new onIntemClick()); 



} 

答えて

0

私は使用して得られた幅と高さの分数使用ウィンドウの幅と高さを固定してしまった:。 DisplayMetricsメトリック=のthis.getResourcesを()getDisplayMetrics(); MyApplication.width = metrics.widthPixels; MyApplication.height = metrics.heightPixels;

高さが一定の場合、PopupWindowはListに新たに追加されなくなりました。

関連する問題