Загрузка...

How to auto fit (auto scale or Zoom) an image in webView of your Android App? - Android Studio code

This video shows the steps to auto fit/ auto scale an image file in the WebView widget of your Android App.

It uses below attributes in the settings of the WebView object to enable the auto-scaling:
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
For testing purpose, it uses below image from the testing page of programmer world website: https://programmerworld.co/selenium-test-page/

https://i0.wp.com/programmerworld.co/wp-content/uploads/2023/05/flower.png?w=977&ssl=1
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com

Complete source code and other details/ steps of this video are posted in the below link:
https://programmerworld.co/android/how-to-auto-fit-auto-scale-or-zoom-an-image-in-webview-of-your-android-app-android-studio-code/
However, the main Java code is copied below also for reference:
package com.programmerworld.autofitimageinwebview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
private EditText editText;
private WebView webView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

editText = findViewById(R.id.editText);
webView = findViewById(R.id.webView);
}

public void buttonWithAutoFit(View view){
webView.loadUrl(editText.getText().toString());

webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
}
public void buttonWithoutAutoFit(View view){
webView.loadUrl(editText.getText().toString());

webView.getSettings().setLoadWithOverviewMode(false);
webView.getSettings().setUseWideViewPort(false);
}
}
--

Видео How to auto fit (auto scale or Zoom) an image in webView of your Android App? - Android Studio code канала Programmer World
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять