如何在Android布局中使用包裹图像的文本浮动图像(右对齐)?

时间:2010-06-07 17:30:04

标签: android image layout floating

这很难解释,但我想要完成的一个例子就是这样:

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生成布局并使用网页视图,但我需要能够在用户点击图片时执行操作。有没有人有任何想法?

提前致谢,

groomsy

2 个答案:

答案 0 :(得分:2)

你可以在没有HTML的情况下做到这一点...... https://github.com/goingkilo/flowing-text-for-android-/blob/master/screenshot3.png

答案 1 :(得分:0)

首先你必须使用一些HTML代码,为你的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>"

创建JSInterface以与模板交互

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

将界面和模板添加到您的网页浏览中!

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);