0

ここに画像の説明を入力ポップアップのレイアウトが次のようなアプリでカスタム ポップアップを作成しました。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

    <ScrollView 
        android:id="@+id/scroller"
        android:layout_margin="4dp"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/popup3"
        android:fadingEdgeLength="0dip"
        android:scrollbars="none">

        <LinearLayout
            android:id="@+id/tracks"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:padding="8dip"/>

    </ScrollView >


    <Button
        android:id="@+id/popup_closer"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_below="@id/scroller"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="0dip"
        android:layout_marginLeft="0dip"
        android:background="@drawable/close_popup"
        android:text=" X " />   
</RelativeLayout>

「トラック」(LinearLayout) に webview を追加します。コードで、このレイアウトのボタンに OnClick イベント リスナーを追加しますが、動作しません。Log.i("clicked",".... "); onclickが起動するかどうかを確認するが、起動しない

追加情報:

ポップアップウィンドウには次のものがあります:

mWindow.setTouchable(true);
mWindow.setFocusable(true);
mWindow.setOutsideTouchable(true);
mWindow.setContentView(mRootView); // mRootView is the inflated layout above.

ポップアップの完全なコードは次のとおりです。

http://pastebin.com/6UQRRJq4

拡張クラスは次のとおりです。

http://pastebin.com/BFb3e6MG

注意: これは「QuickAction ダイアログ」の修正版です。

これが私のポップアップの外観です(同じレイアウトにする別の方法がある場合)、その小さな円形のボタンをクリックできるのは素晴らしいことです)

更新: コードに問題が見つかりました:

View rootView = mInflater.inflate(R.layout.popup_fullscreen,null);
final Button b = (Button) rootView.findViewById(R.id.popup_closer

新しいビューを膨張させるのではなく、膨張したビューの同じインスタンスを使用する必要がありました。

つまり、正しいコードは次のとおりです。

// Changed the View rootView .....etc  to mRootView;
final Button b = (Button) mRootView.findViewById(R.id.popup_closer

ここで別の問題があります。ボタンを 2 回タッチして機能させる必要があります。最初のタッチ イベントがポップアップまたは WebView によって消費され、2 回目が機能するようです。

4

4 に答える 4

0

Remove mWindow.setOutsideTouchable(true), and leave the rest:

mWindow.setTouchable(true);
mWindow.setFocusable(true);
mWindow.setContentView(mRootView); // mRootView is the inflated layout above.

This should allow your PopupWindow to receive touch events, so they get forwarded to the button. Also, make sure you aren't doing any of this after the window has been shown. This must all be called beforehand.

HTH

于 2012-12-27T05:20:33.787 に答える
0

実行時に正しいレイアウトをインフレートし、正しいボタンをクリックすることを確認していますか?

私があなたのコードを見たように、向きに基づいて 2 つの xml ファイルを膨らませようとしています。

コード:

  if (mOrientation == HORIZONTAL) {
        setRootViewId(R.layout.popup_horizontal);
        mAnimStyle  = ANIM_AUTO;
        mChildPos   = 0;
    }
    else if(mOrientation == FULLSCREEN){
            setRootViewId(R.layout.popup_fullscreen);
            mAnimStyle      = ANIM_REFLECT;
        mChildPos   = 0;
    }
    else {
        setRootViewId(R.layout.popup_notifications);
        mAnimStyle  = ANIM_AUTO;
        mChildPos   = 0;
    }

ここで、右のボタンをクリックしたか、別のレイアウトの閉じるボタンをクリックしたかを確認してください。

管理レイアウトとそれを膨らませることを確認してください。

あなたが私の主張を理解してくれることを願っています。

コメントはお気軽にどうぞ。

于 2012-12-27T06:30:20.853 に答える
0

最初にメイン レイアウトの上にポップアップ レイアウトを膨らませます。popupwindow オブジェクトを作成し、onclicklistener 内で関数 showasdropdown を使用して popupwindow を表示します。

以下のサンプル

popuplayout=LayoutInflater.from(getApplicationContext()).inflate(R.layout.popup_layout, null, false); を表示します。PopUpWindow pw = new PopupWindow(popuplayout,260,90,true); pw.showAsDropDown(buttonid, x 座標, y 座標);

これにより、ポップアップが表示されます

于 2012-12-27T05:39:53.347 に答える
0

勝手な推測ですが、代わりに

View rootView = mInflater.inflate(R.layout.popup_fullscreen,null);
final Button b = (Button) rootView.findViewById(R.id.popup_closer);

行う

final Button b = (Button) mRootView.findViewById(R.id.popup_closer);
于 2012-12-27T07:32:58.287 に答える