2010-03-18 53 views

回答

4

爲什麼不直接使用WebView?您將來有更多的自由來以這種方式定製佈局。

如果WebView對於您的用例來說太重,那麼您可能需要手動呈現文本和圖像。您可以在this android-developers thread中找到一些相關信息。

0

完成此操作的另一種方法是製作包含要顯示的文本和圖像的圖像。明顯較重的重量和解決方法。

您可以使用webview和替代方法來加載本地內容。由於1.0 SDK的WebView中不能加載本地內容,而不在這些文章中描述的變通:

http://www.techjini.com/blog/2009/01/10/android-tip-1-contentprovider-accessing-local-file-system-from-webview-showing-image-in-webview-using-content/

http://blog.tourizo.com/2009/02/how-to-display-local-file-in-android.html

羅馬的鏈接是一個線程,說你可以」不要用文字視圖來做,所以這不是一個選項。

15

我寫了一個小部件此: http://code.google.com/p/android-flowtextview/

enter image description here

這個小工具擴展(因此行爲等),一個RelativeLayout的,所以你可以添加子視圖。該類公開了一個setText()方法,該方法允許您設置視圖的文本(純文本或spannable),然後調用invalidate()來渲染文本。該文本將填充子視圖留下的任何空間。

用法示例:

<com.pagesuite.flowtext.FlowTextView 
      android:id="@+id/tv" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:padding="10dip" 
       android:src="@drawable/android" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_marginTop="400dip" 
       android:padding="10dip" 
       android:src="@drawable/android2" /> 
     </com.pagesuite.flowtext.FlowTextView> 

然後在你的代碼:

tv = (FlowTextView) findViewById(R.id.tv);    
Spanned spannable = Html.fromHtml("<html ... </html>"); 
tv.setText(spannable); // using html 
tv.setText("my string"); // using plain text  
tv.invalidate(); // call this to render the text 

總是樂於幫助,如果您有使用這個任何問題,找到我的電子郵件在我的資料

+0

這個速度有多快?它在裏面使用WebView嗎? – 2013-02-05 17:45:56

+0

沒有它的本地,非常快 – 2013-02-06 15:37:47

+0

我不想在這個庫中滾動,而是我想省略文本。任何解決方案 – 2013-04-10 10:21:25