Issue
I am developing an android application and I need to display HTML page.
I managed to do this using the web view as below
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</WebView>
<Button
android:id="@+id/disease_consultation_button"
android:layout_width="@dimen/buttonWidth"
android:layout_height="@dimen/buttonHeight"
android:layout_gravity="right"
android:layout_marginRight="20dp"
style="@style/buttonStyle"
android:text="@string/continue_button" />
</LinearLayout>
and from java code
WebView webView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.disease_web_view_activity);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
String customHtml = "<html><body><h1>Hello, WebView</h1></body></html>";
webView.loadData(customHtml, "text/html", "UTF-8");
}
the button doesn't appear in the view and I don't know why ?
can anyone help me please ?
the view looks like this
EDIT : This is what I did and solved the problem =)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView android:id="@+id/disease_consultation_titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/activityTitle" />
<Button
android:id="@+id/disease_consultation_button"
android:layout_width="wrap_content"
android:layout_height="@dimen/buttonHeight"
android:layout_gravity="right"
android:layout_marginLeft="550dp"
android:layout_marginTop="80dp"
style="@style/buttonStyle"
android:text="@string/request_new_consultation" />
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="150dp" >
</WebView>
</RelativeLayout>
Solution
One thing you can do is to place first button (or another layout to contain more than one items) and then add you WebView e.g.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Hope this helps...
Answered By - umair.ali
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.