2014-12-08 3 views
0

ImageView, TextView 및 WebView가있는보기가 있습니다. XML보기 :화면에 맞게 웹뷰 이미지를 조정하십시오. android

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

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ImageView 
     android:id="@+id/article_details_image_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" /> 

    <TextView 
     android:id="@+id/article_details_title_text_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/article_details_image_view" 
     android:layout_margin="5dp" /> 

    <TextView 
     android:id="@+id/article_details_author_text_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/article_details_title_text_view" 
     android:layout_margin="5dp" /> 

    <TextView 
     android:id="@+id/article_details_date_text_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/article_details_author_text_view" 
     android:layout_margin="5dp" /> 

    <WebView 
     android:id="@+id/article_details_body_text_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/article_details_date_text_view" 
     android:layout_margin="5dp" /> 
</RelativeLayout> 

웹보기 내가 블로그에서 얻을 문자열에서 HTML 본문을 가져옵니다. 그것은 텍스트를 잘 보여하지만 이미지가 너무 커서 WebView를 수평으로 스크롤 할 수 있습니다. 내가 사용하려고했습니다

webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);  

을하지만 아무 일도 발생하지 않습니다와 나는 시도했다 :

WebView browser = (WebView) findViewById(R.id.webview); 
browser.getSettings().setLoadWithOverviewMode(true); 
browser.getSettings().setUseWideViewPort(true);  

그것은 크기를 완벽하게 HTML에서 스케일 이미지를 않습니다,하지만 너무 텍스트를 확장하고 텍스트 크기가 매우됩니다 작은. 텍스트 크기는 같지만 크기가 조정 된 이미지는 어떻게해야합니까?

그것은 응용 프로그램에서 보이는 방법은 HTML에서 어떻게 보이는지

http://i.stack.imgur.com/h0yv2.jpg

: 나는 당신이 부분적으로이 문제를 해결하는 데 도움이 될 것입니다

http://i.stack.imgur.com/oFVkE.jpg

+0

HTML에 스타일을 추가해야합니다 (예 :'img {display : inline; 높이 : 자동; max-width : 100 %;}' – orium

+0

나는 너의 예제를 사용하고 최대 너비를 장치 디스플레이 너비로 설정했다. 고맙습니다. – Roo

답변

0

합니다. WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING에 대해 들었습니까?이 정보는 Android API 레벨 19에서 이라고 소개되었습니다. 그러면 웹 뷰의 텍스트 및 이미지 문제가 해결됩니다. 안드로이드 버전 4.4 이상 작동합니다.

webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING); 

아래의 버전에는 아직 완벽한 해결책이 없습니다. 아래 토론을 확인하십시오.

WebView : WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING : Below Andoird 4.4?

또한 당신이 webSettings.setDefaultFontSize을 사용할 수 있습니다 ((int)를 fontSize는); 웹 뷰에서 텍스트 크기를 관리하는 방법. 희망이 당신을 도울 것입니다.

+0

아무 것도 바뀌지 않았습니다. 내 XML을 변경해야합니까? – Roo

+0

Roo, 내 대답을 업데이트 해주세요. ** webSettings.setDefaultFontSize ((int) fontSize) ** 메소드를 사용해보십시오. –

관련 문제