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

2024-04-07

我目前正在开发电子商务 Android 应用程序,我需要在滚动时修复工具栏。

正如我附上下面的屏幕截图。滚动操作栏时需要固定,正文内容滚动到工具栏后面

这是布局 xml:

<LinearLayout
    android:id="@+id/container_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <include
        android:id="@+id/toolbar_reg"
        layout="@layout/app_bar" />
</LinearLayout>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="3dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?android:attr/actionBarSize"
        android:background="#ffffff"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:layout_marginTop="15dp"
            android:src="@drawable/logo" />


        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/input_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:hint="@string/reg_name"
                android:singleLine="true" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/input_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:hint="@string/reg_email"
                android:inputType="textEmailAddress" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/input_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:hint="@string/reg_password"
                android:inputType="textPassword" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_cpassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/input_cpassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:hint="Confirm Password"
                android:inputType="textPassword" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_mobile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/input_mobile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:hint="Mobile No"
                android:inputType="number" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_dob"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/input_dob"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:hint="Date of Birth" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_address"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/input_address"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Permanent Address" />
        </android.support.design.widget.TextInputLayout>

        <Button
            android:id="@+id/btn_signup"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="25dp"
            android:background="@color/colorPrimary"
            android:text="@string/btn_sign_up"
            android:textColor="@android:color/white" />

        <TextView
            android:id="@+id/link_login"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="150dp"
            android:layout_marginTop="15dp"
            android:gravity="center"
            android:text="@string/req_login"
            android:textSize="16dp" />

    </LinearLayout>
</ScrollView>

您应该构建 XML,使其如下所示:

Relative layout
|-->Toolbar    (android:id="@+id/toolbar")
|-->ScrollView (android:layout_below="@id/toolbar")
    |-->ViewGroup(For example, CoordinatorLayout)
        |-->Child
        |-->Child
        |-->Child

示例代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:theme="@style/WelcomeActivityTheme.Toolbar"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        />
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        />
    </ScrollView>
</RelativeLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在滚动 android 时固定工具栏 的相关文章

  • “_加载小部件时出现问题”消息

    加载小部件时 如果找不到资源或其他内容 则会显示 加载小部件时出现问题 就这样 惊人的 此消息保留在主屏幕上 甚至没有说明加载时遇到问题的小部件 我通过反复试验弄清楚了这一点 但我想知道发生这种情况时是否有任何地方可以找到错误消息 Andr
  • Android 2.2 SDK - Droid X 相机活动无法正常完成

    我注意到我在 Droid X 上调用的默认相机活动与我的 Droid 和 Nexus One 上的默认相机活动看起来不同 在 Droid 和 Nexus One 上选择 确定 后 活动将完成 Droid X 有一个 完成 按钮 它将带您返回
  • 将正确的上下文传递给 greendao 的 OpenHelper 构造函数

    如果我理解正确的话 在使用数据库时 我必须执行以下操作 DaoMaster OpenHelper helper new DaoMaster OpenHelper this test db null Override public void
  • 毕加索动画加载图像

    我有以下代码在毕加索中加载图像 使用可绘制的占位符在图像下载时显示 不过 我想要的是一个动画旋转进度条样式的旋转器 它可以在图像加载时不断地旋转 就像我在大多数专业应用程序中看到的那样 毕加索似乎不支持这一点 只支持静态图像可绘制 有没有办
  • FileNotFoundException:/存储/模拟/0/Android

    我尝试这个文件写入器 读取器代码段进行测试 File file new File Environment getExternalStorageDirectory LM lm lisdat 01 txt FileOutputStream ou
  • 使用 RecyclerView 适配器在运行时更改布局屏幕

    我有两个布局文件 如下所示 如果列表中存在数据 则我显示此布局 当列表为空时 我会显示此布局 现在我想在运行时更改布局 当用户从列表中删除最后一项时 我想将布局更改为第二张图片中显示的 空购物车布局 In getItemCount Recy
  • 以编程方式更新 Android 中的联系人姓名和电话号码

    我创建一个应用程序来读取 更新 删除联系人详细信息 这是更新联系人姓名和电话号码的问题 有人可以帮助我吗 我该怎么做 我正在使用以下代码 但它不起作用 Override public View onCreateView LayoutInfl
  • 应用内结算错误

    我的 UNMANAGED 应用内购买无法正常工作 在它完美运行之前 我可以使用测试帐户成功购买 但它突然不起作用了 因为我记得我对商家帐户所做的只是添加更多 2 4 个测试帐户 添加后 我的应用内购买将不起作用 所以我更新了公钥并上传了一个
  • 如何强制从本机代码打开 Android 软键盘?

    我有一个游戏 当用户触摸屏幕时 它使用从 C 到 Java 的回调来强制打开软键盘 Java代码很简单是这样的 this inputMethodManager toggleSoftInput InputMethodManager SHOW
  • 如何查看 Android 上的 Wi-Fi 是否已连接?

    我什至不希望我的用户尝试下载某些内容 除非他们连接了 Wi Fi 然而 我似乎只能判断是否启用了 Wi Fi 但他们仍然可以有 3G 连接 android net wifi WifiManager m WifiManager getSyst
  • 如何以编程方式启动 ssh 服务器 android,以及如何获取连接到设备的用户名和密码

    我正在开发像这样的应用程序sshdroid 我想在 Android 操作系统上打开 ssh 连接 并且我想从电脑连接应用程序 我使用了 JSCH lib 但是这个lib用于将android连接到pc 我的要求是pc到android 任何人都
  • 为什么Android应用程序在发布到市场后尺寸会增加?

    我最近在 Android 市场上发布了我的应用程序 显示应用程序大小为 5 4MB 而实际 apk 大小为 2 8MB 为什么显示多出2MB 我应该如何限制我的应用程序大小 请帮我 您的应用程序大小会增加 因为您使用了复制保护选项ON在发布
  • java.lang.IllegalArgumentException:找不到片段的 id 0x1020002 (android:id/content) 的视图

    我正在尝试从一个片段移动到另一个片段 它在片段事务期间显示以下错误 java lang IllegalArgumentException No view found for id 0x1020002 android id content f
  • Espresso 和 Proguard 的 Java.lang.NoClassDefFoundError

    我对 Espresso 不太有经验 但我终于成功地运行了它 我有一个应用程序需要通过 Proguard 缩小才能处于 56K 方法之下 该应用程序以 3 秒的动画开始 因此我需要等到该动画结束才能继续 这就是我尝试用该方法做的事情waitF
  • onBackPressed 隐藏 不破坏 Activity

    我知道如何取消后退按键 以便活动 主窗口保持可见 public void onBackPressed return 我的目标是隐藏该活动 但是 在没有完成它的情况下 您如何在 onBackPressed 事件中做到这一点 即我想达到 onP
  • 将图像添加到自定义 AlertDialog

    我制作了一个 AlertDialog 让用户可以从我显示的 4 个选项中选择一个 前 3 个让他们在单击号码时直接拨打号码 第 4 个显示不同的视图 现在看起来是这样的 由于第四个选项的目的是不同的任务 我想让它看起来不同 因为用户可能会感
  • 无法将类型“System.IO.Stream”隐式转换为“Java.IO.InputStream”

    我提到了一些类似的问题 但没有一个涉及IO 当我使用时 我在java中使用了相同的代码Eclipse 那次就成功了 但现在我尝试在中使用这段代码Mono for Android C 它不起作用 我正在尝试运行此代码来创建一个InputStr
  • JSON 到 hashmap (杰克逊)

    我想将 JSON 转换为 HashMapJackson http jackson codehaus org 这是我的 JSON String json Opleidingen name Bijz trajecten zorg en welz
  • 在 Honeycomb Android 3.0 中显示 Action Bar 菜单项的图标

    我正在使用 Honeycomb android 3 0 开发 Android 应用程序 我正在尝试在 Action Bar 中显示菜单 菜单有一个图标和标题 当我们单击菜单项时 它会以下拉列表的形式显示其项目 它是下拉列表中带有项目名称但不
  • Android 自定义警报对话框中的 OnClickListener

    我是一个自学成才的初学者 感谢耐心 谢谢 在 Eclipse 中 我使用自己的 xml 文件 custom dialog 创建了一个自定义警报对话框 称为 usernamealert 如果用户尚未输入用户名 即 username lengt

随机推荐