【问题标题】:Android: EditText on top of WebView?Android:WebView 之上的 EditText?
【发布时间】:2011-07-16 04:21:16
【问题描述】:

我想模仿默认 android 浏览器的行为 - 一旦用户向下滚动,顶部的 EditText(地址栏)将开始“消失”。我现在唯一能想到的就是将 EditText 和 WebView 放在一个 ScrollView 中,但这会产生其他问题,不推荐。

你怎么看?

【问题讨论】:

    标签: android webview scroll android-edittext scrollview


    【解决方案1】:

    通过扩展 WebView 并覆盖 onScrollChanged() 创建自定义 View。只需稍加计算,您就可以完成任务。

    【讨论】:

    • 所以基本上你的意思是我必须将地址栏“推”出屏幕边界?难道就没有什么“优雅”的方法吗?
    • 这就是我的意思。根据当前滚动更改编辑框的位置。没有,我知道。
    【解决方案2】:

    您的 ScrollView 会导致什么问题?这个应该可以正常工作:

    <?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>
    

    【讨论】:

    • 在我看来,这个独立的解决方案由于 WebView 的丑陋滚动而提供了糟糕的用户体验。在这里查看我的答案,以便在将 webview 放置在滚动视图中时提供更好的用户体验 - TolerantScrollView
    猜你喜欢
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 2021-09-19
    • 2014-11-14
    • 1970-01-01
    相关资源
    最近更新 更多