正在尝试在我的WebView的中心放置一个小的图像,以便当Webview不加载任何内容时,该图像将可见。问题是图像占据了webview的整个宽度和高度,我尝试了很多方法将其放置在中央,但没有一个起作用。而且我最后一次尝试不允许该应用程序吃午餐。
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);
答案 0 :(得分: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>