How to place small image on centre of webview background

0

Am trying to place a small image on the centre of my WebView so when webview doesn't load any content the image will be visible. The problem is that the image take the full width and height of the webview, I have tried many things to place it on the centre but none of it worked. And my last attempt doesn't allow the app to lunch.

Activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary"
        tools:context=".MainActivity"
        android:id="@+id/activity_main">
    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary"
        android:layout_gravity="center"
        android:id="@+id/AppId">
    </WebView>
</RelativeLayout>

MainActivity.java

    webview.setBackgroundResource(R.drawable.wbg_icon);
    webview.setBackgroundColor(0x00000000);

    RelativeLayout relativeLayout = new RelativeLayout(MainActivity.this);
    RelativeLayout.LayoutParams layoutParams= new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
    layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, 1);
    relativeLayout.addView(webview, layoutParams);
android
android-layout
webview
asked on Stack Overflow Mar 21, 2019 by Peter

1 Answer

0
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    tools:context=".MainActivity"
    android:id="@+id/activity_main">
    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary"
        android:layout_gravity="center"
        android:id="@+id/AppId">
    </WebView>
    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:src="@drawable/ic_launcher"/>
</FrameLayout>
answered on Stack Overflow Mar 21, 2019 by Shanto George

User contributions licensed under CC BY-SA 3.0