2017-06-14 100 views
1

在我的应用程序中,WebView上有一个ImageButton,但当我将页面滚动到底部时,它仍然位于顶部。我怎样才能解决这个问题?在webview上设置图像按钮

<LinearLayout android:layout_height="match_parent" 
     android:layout_width="fill_parent" 
     android:orientation="vertical"> 

     <WebView 
      android:layout_height="wrap_content" 
      android:id="@+id/webView" 
      android:layout_width="fill_parent"> 

      <ImageButton 
       android:id="@+id/imageButton" 
       android:layout_width="88dp" 
       android:layout_height="88dp" 
       android:layout_x="292dp" 
       android:layout_y="450dp" 
       android:background="@drawable/downloadarrow" /> 
     </WebView>  
</LinearLayout> 

回答

0

尝试使用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> 
+0

但它并不显示按钮 – th3gr3yman

+0

@ th3gr3yman尝试更换位置,将按钮的WebView – Tony

+0

之后是相同的东西 – th3gr3yman