如何在Android版式的顶部固定应用栏和Edittext

杰森

我有这样的布局:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    xmlns:app="http://schemas.android.com/apk/res-auto">




    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:showIn="@layout/activity_show" tools:context="com.example.bimpc1.myapp.ShowActivity"
        android:background="@color/backgrndclr"
        >


        <android.support.v7.widget.Toolbar
            android:id="@+id/my_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            xmlns:android="http://schemas.android.com/apk/res/android" />
        <View
            android:layout_width="fill_parent"
            android:layout_height="30dp">
        </View>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingLeft="10dp"
            android:paddingRight="10dp">




            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/et_word"
                android:ems="14"
                android:hint="Search"
                android:drawableBottom="@color/bottomcolor"/>

            <ImageButton
                android:id="@+id/btn_bring"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:src="@drawable/search"
                android:background="@color/buttonbckgrndclr"
                android:paddingRight="10dp"
                android:paddingLeft="10dp"
                android:paddingTop="10dp"
                android:paddingBottom="5dp"
                />

        </LinearLayout>
<!-- And lots of other view elements -->
    </LinearLayout>
</ScrollView>

它在屏幕上看起来像这样:

在此处输入图片说明

我希望该栏以及该搜索的编辑文本和搜索按钮固定在屏幕顶部。我的意思是当用户向下滚动时它们不应该消失。我该如何实现?我用谷歌搜索了我的问题,但找不到解决方案。谢谢。

恩恩萨拉

移至ScrollView两个元素下方:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_show" tools:context="com.example.bimpc1.myapp.ShowActivity"
    android:background="@color/backgrndclr"
    >


    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        xmlns:android="http://schemas.android.com/apk/res/android" />
    <View
        android:layout_width="fill_parent"
        android:layout_height="30dp">
    </View>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="10dp"
        android:paddingRight="10dp">

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/et_word"
            android:ems="14"
            android:hint="Search"
            android:drawableBottom="@color/bottomcolor"/>

        <ImageButton
            android:id="@+id/btn_bring"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:src="@drawable/search"
            android:background="@color/buttonbckgrndclr"
            android:paddingRight="10dp"
            android:paddingLeft="10dp"
            android:paddingTop="10dp"
            android:paddingBottom="5dp"
            />

    </LinearLayout>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        xmlns:app="http://schemas.android.com/apk/res-auto">    

        <!-- And lots of other view elements -->
        </ScrollView>
</LinearLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在离子中如何在顶部添加固定的徽标栏

来自分类Dev

如何使导航栏固定在顶部

来自分类Dev

bootstrap导航栏固定顶部和身体填充顶部

来自分类Dev

左侧的固定侧边栏菜单和顶部的固定标题

来自分类Dev

如何在CSS中制作高度可变的固定顶部菜单栏?

来自分类Dev

如何在引导程序 4 中居中固定顶部导航栏

来自分类Dev

向下滚动时如何使标题和导航栏都固定在顶部

来自分类Dev

如何在滚动Android时固定工具栏

来自分类Dev

如何在Android中单击按钮上的EditText上应用撤消和重做操作

来自分类Dev

如何在Android中使用Material Design在EditText和TextView中应用shapeAppreanace

来自分类Dev

如何在Android中单击按钮上的EditText上应用撤消和重做操作

来自分类Dev

如何在工具栏的中间和顶部放置工具栏(vue,vuetify)

来自分类Dev

具有固定在顶部的导航栏和Bootstro的Bootstrap

来自分类Dev

具有固定在顶部的导航栏和Bootstro的Bootstrap

来自分类Dev

如何在Phonegap移动应用中同步android中的离子导航栏和硬件按钮

来自分类Dev

删除导航顶部和底部的Android栏

来自分类Dev

Android 和 React Native 顶部导航栏

来自分类Dev

如何在GNOME中的应用程序的顶部栏中更改名称?

来自分类Dev

如何正确使导航栏保持固定在屏幕顶部?

来自分类Dev

滚动时如何将导航栏固定在顶部?

来自分类Dev

如何正确使导航栏保持固定在屏幕顶部?

来自分类Dev

如何使导航栏固定在页面顶部且不可重叠

来自分类Dev

Windows Phone 8应用程序-如何更改时钟和顶部栏图标的颜色

来自分类Dev

如何在顶部栏添加内容?

来自分类Dev

如何在背景顶部添加导航栏?

来自分类Dev

如何在软件顶部栏中删除?

来自分类Dev

如何在没有固定宽度的情况下使控件的顶部和左侧对齐?

来自分类Dev

如何在桌面屏幕外部的顶部,底部,右侧和左侧固定空白?

来自分类Dev

导航栏固定在顶部

Related 相关文章

  1. 1

    在离子中如何在顶部添加固定的徽标栏

  2. 2

    如何使导航栏固定在顶部

  3. 3

    bootstrap导航栏固定顶部和身体填充顶部

  4. 4

    左侧的固定侧边栏菜单和顶部的固定标题

  5. 5

    如何在CSS中制作高度可变的固定顶部菜单栏?

  6. 6

    如何在引导程序 4 中居中固定顶部导航栏

  7. 7

    向下滚动时如何使标题和导航栏都固定在顶部

  8. 8

    如何在滚动Android时固定工具栏

  9. 9

    如何在Android中单击按钮上的EditText上应用撤消和重做操作

  10. 10

    如何在Android中使用Material Design在EditText和TextView中应用shapeAppreanace

  11. 11

    如何在Android中单击按钮上的EditText上应用撤消和重做操作

  12. 12

    如何在工具栏的中间和顶部放置工具栏(vue,vuetify)

  13. 13

    具有固定在顶部的导航栏和Bootstro的Bootstrap

  14. 14

    具有固定在顶部的导航栏和Bootstro的Bootstrap

  15. 15

    如何在Phonegap移动应用中同步android中的离子导航栏和硬件按钮

  16. 16

    删除导航顶部和底部的Android栏

  17. 17

    Android 和 React Native 顶部导航栏

  18. 18

    如何在GNOME中的应用程序的顶部栏中更改名称?

  19. 19

    如何正确使导航栏保持固定在屏幕顶部?

  20. 20

    滚动时如何将导航栏固定在顶部?

  21. 21

    如何正确使导航栏保持固定在屏幕顶部?

  22. 22

    如何使导航栏固定在页面顶部且不可重叠

  23. 23

    Windows Phone 8应用程序-如何更改时钟和顶部栏图标的颜色

  24. 24

    如何在顶部栏添加内容?

  25. 25

    如何在背景顶部添加导航栏?

  26. 26

    如何在软件顶部栏中删除?

  27. 27

    如何在没有固定宽度的情况下使控件的顶部和左侧对齐?

  28. 28

    如何在桌面屏幕外部的顶部,底部,右侧和左侧固定空白?

  29. 29

    导航栏固定在顶部

热门标签

归档