android在webview末尾添加一个按钮(重叠网页)
我有一个带有网址的网络视图, 该网站大约1000像素(可以更改) 我想在URL的末尾显示一个按钮(在页脚重叠处) 如果无法执行上述操作,则应始终在“主页”和“返回”按钮上方的webview底部显示一个按钮 下面是我试过的 提前感谢您的帮助和支持android在webview末尾添加一个按钮(重叠网页),android,html,button,webview,Android,Html,Button,Webview,我有一个带有网址的网络视图, 该网站大约1000像素(可以更改) 我想在URL的末尾显示一个按钮(在页脚重叠处) 如果无法执行上述操作,则应始终在“主页”和“返回”按钮上方的webview底部显示一个按钮 下面是我试过的 提前感谢您的帮助和支持 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" andr
<?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>
试试这个:
<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>
尝试使用垂直方向的线性布局,而不是相对布局。相对布局是在相对位置显示子视图的视图组。您试图在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>
如果我理解正确,您提到要用自己的按钮替换网站的页脚,对吗?你可以这样做。。它将作为静态按钮放置在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>
谢谢ZeroOne@ZeroOne但是这个按钮会随着webview滚动/移动吗??我想我会保持静态。我希望按钮在底部,并与网站一样滚动webview。怎么做?@B.shruti。。由于RL中的android:layout\u alignParentBottom=“true”,它将保持底部。。尝试将其放在scrollview中,并固定webview的高度。。当您需要处理onTouch方法时,这将是一个棘手的部分
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);
}