如何在 Android 布局中拥有浮动图像(右对齐)以及环绕图像的文本?

发布于 2024-09-04 09:21:38 字数 294 浏览 2 评论 0原文

这有点难以解释,但我想要完成的示例如下:

Here is some text | image |
that is printed   |       |
out in a view and ---------
it is wrapped around an
image that is floating and
right aligned.

我考虑过在 html 中生成布局并使用 Web 视图,但我需要能够在用户单击时执行操作在图像上。有人有什么想法吗?

预先感谢,

新郎

It's kind of hard to explain, but an example of what I'm wanting to accomplish is like this:

Here is some text | image |
that is printed   |       |
out in a view and ---------
it is wrapped around an
image that is floating and
right aligned.

I thought about generating the layout in html and using a web view, but I need to be able to perform an action when the user clicks on the image. Does anyone have any ideas?

Thanks in advance,

groomsy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满天都是小星星 2024-09-11 09:21:38

首先,您必须使用一些 html 代码,为您的 web 视图创建模板...

     String TemplateHTML =

"<div id=\"content\">[Replace with your CONTENT]</div><div id=\"myimage\"><a id=\"mylink\" onClick=\"window.demo.clickOnAndroid()\"><img id=\"myImage\" src=\"[Replace your image URL path]\" /></a></div>"

创建 JSInterface 与您的模板交互,

    final class myJavaScriptInterface {
        myJavaScriptInterface () {
        }
        public void clickOnAndroid() {
            mHandler.post(new Runnable() {
                public void run() {
Log.i("myJavaScriptInterface " ,"Jorge is Clickin the image!!! =D");        
                }
            });
        }
    }

将界面和模板添加到您的 web 视图!

MyWebView.addJavascriptInterface(new myJavaScriptInterface (), "demo");     
    MyWebView.loadDataWithBaseURL(null, TemplateHTML, "text/html", "utf-8", null);
    WebSettings webSettings = WebContent.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true);   

first you must work with some html code, creating a template for your webview...

     String TemplateHTML =

"<div id=\"content\">[Replace with your CONTENT]</div><div id=\"myimage\"><a id=\"mylink\" onClick=\"window.demo.clickOnAndroid()\"><img id=\"myImage\" src=\"[Replace your image URL path]\" /></a></div>"

Create JSInterface to interact with your template

    final class myJavaScriptInterface {
        myJavaScriptInterface () {
        }
        public void clickOnAndroid() {
            mHandler.post(new Runnable() {
                public void run() {
Log.i("myJavaScriptInterface " ,"Jorge is Clickin the image!!! =D");        
                }
            });
        }
    }

add the interface and your Template to your webview!

MyWebView.addJavascriptInterface(new myJavaScriptInterface (), "demo");     
    MyWebView.loadDataWithBaseURL(null, TemplateHTML, "text/html", "utf-8", null);
    WebSettings webSettings = WebContent.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true);   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文