嘗試使用ConstraintLayout
如:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.test.mytest.MainActivity"
tools:showIn="@layout/app_bar_main">
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="148dp"
app:layout_constraintBottom_toBottomOf="@+id/webView1"
android:layout_marginBottom="8dp" />
<WebView
android:id="@+id/webView1"
android:layout_width="368dp"
android:layout_height="495dp"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="8dp" />
</android.support.constraint.ConstraintLayout>
這允許按鈕留在的位置,同時您滾動的WebView
編輯:
您是否試過將按鈕移出webview?
<LinearLayout android:layout_height="match_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="88dp"
android:layout_height="88dp"
android:layout_x="292dp"
android:layout_y="450dp"
android:background="@drawable/ic_menu_gallery" />
<WebView
android:layout_height="wrap_content"
android:id="@+id/webView"
android:layout_width="fill_parent">
</WebView>
</LinearLayout>
如果你想全屏模式,只需將的LinearLayout更改爲RelativeLayout的:
<RelativeLayout android:layout_height="match_parent"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</RelativeLayout>
但它並不顯示按鈕 – th3gr3yman
@ th3gr3yman嘗試更換位置,將按鈕的WebView – Tony
之後是相同的東西 – th3gr3yman