Reading page
First, start with the layout. The reading interface adopts the RelativeLayout Layout mode. The purpose is to keep a menu key under the screen for easy touch operations.
Next we will gradually explain the code for some page la s on the screen:
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android=
- "http://schemas.android.com/apk/res/android"
- androidrientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#FFdbdbdb"
- >
Set full screen and background color
- <WebView android:id="@+id/webkit"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#FFdbdbdb"
- />
The full-screen WebView control, that is, the browser control, also sets the background color.
- <Button android: layout_width = "wrap_content"
- Android: id = "@ + id/Button01"
- Android: layout_centerHorizontal = "true"
- Android: layout_centerInParent = "true"
- Android: layout_alignParentRight = "false"
- Android: layout_alignWithParentIfMissing = "true"
- Android: layout_height = "wrap_content"
- Android: layout_alignBottom = "@ layout/main" android: text = "menu">
- </Button>
The menu key settings, layout_centerHorizontal layout_alignParentRight button settings ensure that the menu key remains in the middle. android: layout_alignBottom = "@ layout/main" sets the menu key at the bottom of the page.
- <Button android: layout_width = "wrap_content"
- Android: id = "@ + id/ButtonUp"
- Android: layout_centerHorizontal = "true"
- Android: layout_centerInParent = "false"
- Android: layout_alignParentLeft = "true"
- Android: layout_alignWithParentIfMissing = "true"
- Android: layout_height = "wrap_content"
- Android: layout_alignBottom = "@ layout/main" android: text = "Previous Page">
- </Button>
- <Button android: layout_width = "wrap_content"
- Android: id = "@ + id/ButtonDown"
- Android: layout_centerHorizontal = "true"
- Android: layout_centerInParent = "false"
- Android: layout_alignParentRight = "true"
- Android: layout_alignWithParentIfMissing = "true"
- Android: layout_height = "wrap_content"
- Android: layout_alignBottom = "@ layout/main" android: text = "next page">
- </Button>
- </RelativeLayout>
Similarly, the buttons on the top and bottom pages are set on one left and one right.
Now you have prepared the page.
The advantage of RelativeLayout layout is that you can place the button you need on the relative position of the screen. It is suitable for mobile phones of different screen sizes to adopt unified code operations, reducing the burden of transplantation. The layout is only at the front and bottom of the screen, and can also be at the center and top of the screen.
Basic use of webView controls
The browser control is webView. The following describes how to set and monitor the webView control: webView is not available in j2s, which is similar to Symbian and. net CF provides a function-like browser control, which can be used to directly access the webpage or display the input HTML string. The function is powerful, similar to that of Symbian or. net CF browser controls have the following advantages:
1. Powerful functions: supports CSS, Java script, and other HTML languages, so that the page can be more beautiful.
2. the browser controls can be set in great detail, such as the font size, background color, and scroll bar style.
3. Capture all browser operations, such as clicking a URL to open or close a URL
4. Well integrated layout.
5. Even webView can interact with JS.
- Loading and using SDCard in OPhone Simulator
- How to get started with Ophone Widget SDK
- Quick Start: getting started with Ophone and Android
- How to port a j2-api to OPhone
- Combat between Android platform and OPhone
After using the webView layout page, we first get the webView instance, and browser is the webView object:
Browser = (WebView) findViewById (R. id. webkit );
After obtaining the instance, we define WebSettings for browser. WebSettings is the specific setting class of WebView, which can be very detailed.
WebSettings bs = browser. getSettings ();
The webView setting object is obtained. Set the browser control