18

PhoneGap が提供する WebView の上にネイティブ UI ビューをレンダリングする必要がある phonegap プラグインを構築しています。iOS では、これは非常に簡単です。ビューを作成し、それを PhoneGap の webView の scrollView に追加するだけです。これにより、webView の上にコントロールがレンダリングされ、HTML コンテンツと共にスクロールできるようになります (この例では UIButton を使用していますが、これをカスタム UI コントロールに適用することに注意してください)。

-(void)createNativeControl:(CDVInvokedUrlCommand *)command
{
    NSDictionary* options = [command.arguments objectAtIndex:0];
    NSNumber* x = [options objectForKey:@"x"];
    NSNumber* y = [options objectForKey:@"y"];
    NSNumber* width = [options objectForKey:@"width"];
    NSNumber* height = [options objectForKey:@"height"];

    CGRect rect = CGRectMake([x floatValue], [y floatValue], [width floatValue], [height floatValue]);
    self._nativeControl = [UIButton buttonWithType:UIButtonTypeSystem];
    self._nativeControl.frame = rect;

    [self._nativeControl addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self._nativeControl setTitle:@"Click me" forState:UIControlStateNormal];
    [self.webView.scrollView addSubview:self._nativeControl];

    CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
    [self.commandDelegate sendPluginResult:result callbackId:command.callbackID];
}

Androidでほぼ同等のことを試みましたが、成功しませんでした。これが私の最近の試みです:

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    System.out.println(String.format("%s action called", action));

    if ("echo".equals(action)) {
        String message = args.optString(0);
        this.echo(message, callbackContext);
        return true;
    } else if ("createNativeControl".equals(action)) {
        this.createNativeControl(callbackContext);
        return true;
    }

    return false;
}

private void createNativeControl(CallbackContext callbackContext) {
    // Find the frame layout parent and place the control on top - theoretically
    // this should appear on TOP of the webView content since the TextView child is
    // added later
    FrameLayout frameLayout = (FrameLayout) webView.getParent().getParent();

    TextView view = new TextView(frameLayout.getContext());
    view.setText("Hello, Android!");
    view.setVisibility(View.VISIBLE);

    frameLayout.addView(view, 100,100);
    callbackContext.success();
}

Androidでこれを達成するにはどうすればよいですか?

4

3 に答える 3

-1

ビューの順序を確認しようとしましたか? 多分それはあなたのウェブビューに重なっています

//webview を隠す
//webview.setVisibility(View.GONE); // 新しいビューが表示されるかどうかをテストする
webview.setZOrderOnTop(true);

//新しいビューを表示 myView.setVisibility(View.VISIBLE);

myView.bringToFront();

この行がビューを追加できる有効な親を取得することを 100% 確信していると仮定します。

FrameLayout frameLayout = (FrameLayout) webView.getParent().getParent();

于 2014-05-22T11:51:00.843 に答える