Android: EditText on top of WebView?
I would like to imitate the behavior of the default android browser - The EditText (the address bar) on top will start to "disappear" once the user scrolls down. The only thing I can think of right now is to put the EditText and the WebV开发者_如何学编程iew in a ScrollView but that would create other problems, and is not recommended.
What do you think?
Create a custom View by extending WebView and override onScrollChanged(). With a little calculations you can accomplish your task.
What problems does your ScrollView cause? This one should work fine:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0" android:orientation="vertical">
<ScrollView android:layout_width="fill_parent" android:layout_gravity="top" android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0" android:orientation="vertical">
<EditText android:layout_width="fill_parent" android:id="@+id/editText1" android:text="yourtexthere" android:layout_gravity="bottom" android:layout_height="wrap_content">
</EditText>
<WebView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/myWebView"></WebView>
</LinearLayout>
</ScrollView>
</LinearLayout>
精彩评论