When we browse the details of Taobao products, we will get back to the top of this feature, let's talk about the simple implementation of this feature
<framelayout xmlns:android= "http://schemas.android.com/apk/res/android"
Android:layout_width= " Match_parent "
android:layout_height=" match_parent
<scrollview
android:id= "@+id/sc"
Android : layout_width= "match_parent"
android:layout_height= "wrap_content"
android:fillviewport= "true"
<linearlayout
android:layout_width= "match_parent"
android:layout_height= "match_parent"
Android:o rientation= "vertical"
<webview
android:id= "@+id/wb"
android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
</webview>
</linearlayout>
</scrollview
<button
android:id= "@+id/bt"
android:layout_width= "match_parent"
Android:layout_ height= "50DP"
android:background= "@android: Color/black"
android:layout_gravity= "Bottom"
android:text= "Point me Up"
android:textcolor= "#ffffff"
/>
</framelayout>
Layout of the outermost use framelayout, and then set on the ScrollView, but must pay attention to ScrollView high can only be wrap_content, or click Back to the bottom no effect.
The code is as follows
public class Mainactivity extends Appcompatactivity {
Private ScrollView SC;
Private WebView WB;
Private Button BT;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Sc= (ScrollView) Findviewbyid (R.id.sc);
wb= (WebView) Findviewbyid (R.ID.WB);
bt= (Button) Findviewbyid (R.ID.BT);
Bt.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
Sc.post (New Runnable () {
@Override
public void Run () {
Sc.post (New Runnable () {
public void Run () {
Back to the top of
Sc.fullscroll (SCROLLVIEW.FOCUS_UP);
}
});
}
});
}
});
Initview ();
}
private void Initview () {
String url = "https://www.111cn.net/";
WebSettings websettings = Wb.getsettings ();
Websettings.setlayoutalgorithm (WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
Websettings.setjavascriptenabled (TRUE); To set the WebView property to execute a JavaScript script
Setting Access to Files
Websettings.setallowfileaccess (TRUE);
Websettings.setbuiltinzoomcontrols (false);//setting whether the Zoom tool is displayed
Wb.loadurl (URL);
Wb.setwebviewclient (New Webviewclient ());
}
}
Implementation of the effect as shown, I am here to use WebView link Baidu Web page, other controls are the same