android在webview末尾添加一个按钮(重叠网页)

时间:2016-12-26 19:19:10

标签: android html button webview

我有一个带有网站网址的网页视图, 该网站约1000px(可以更改) 我想在URL的末尾显示一个按钮(在页脚重叠上)

如果上述情况不可行,则应始终在我们的主页和后退按钮上方的webview底部显示一个按钮。

以下是我的尝试。

提前感谢您的帮助和支持。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">

<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button
        android:id="@+id/buttonUrl"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:text="XXX" />

</WebView>

4 个答案:

答案 0 :(得分:0)

试试这个:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <WebView
        android:id="@+id/webview1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/btnOk"
        android:layout_weight="1" />

    <Button
        android:id="@+id/btnOk"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center_horizontal"
        android:text="Ok" />
</LinearLayout>

答案 1 :(得分:0)

尝试使用垂直方向的线性布局而不是相对布局..

答案 2 :(得分:0)

RelativeLayout 是一个视图组,用于显示相对位置的子视图。您试图在weview中添加按钮,这是错误的实现。

<?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="horizontal">
    <Button
        android:id="@+id/buttonUrl"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:text="XXX" />
    <WebView android:id="@+id/webView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
  </RelativeLayout>

答案 3 :(得分:0)

如果我理解正确,你提到你想用你自己的按钮替换网站的页脚吗?你可以这样做..它将作为静态按钮覆盖webview布局。您需要确保您的页脚高度与您需要覆盖的按钮相同。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <WebView android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <Button
        android:id="@+id/buttonUrl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        style="?attr/borderlessButtonStyle"
        android:background="@android:color/white"
        android:text="XXX" />
</RelativeLayout>

使用以下方法将按钮高度调整为与网站页脚相同

前:

buttonUrl.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, pxToDP(1000)));


public static int pxToDp(int px) {
    return (int) (px / Resources.getSystem().getDisplayMetrics().density);
}

public static int dpToPx(int dp) {
    return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}