android - 如何将自定义 ActionBar 设置为 ScrollView 布局中的固定顶部位置?

标签 android eclipse android-layout

即使在滚动长数据屏幕时它仍保持在屏幕顶部可见,我如何以某种方式设置此操作栏?

工具栏.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

小伙伴们请看我的更新: 我尝试了一切,但似乎 actionBar 之后的下一个组件没有设置在 actionBar 之后而是在它后面:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/background_telas"
android:orientation="vertical" >

<include layout="@layout/toolbar" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

enter image description here

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/actionBar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/actionBarBackgroundColor"
    app:contentInsetEnd="0dp"
    app:contentInsetStart="0dp" >
</android.support.v7.widget.Toolbar>

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#A0A09F" />

项目( eclipse ): Project in eclipse IDE

屏幕停止: Screen stopped showing acationbar on top

屏幕向上滚动: Screen scrolled up showing the actionbar going up with other data

Java:

    Toolbar actionBar = (Toolbar) findViewById(R.id.actionBar);
    actionBar.setTitle("ProTaxi Passageiro");
    actionBar.setSubtitle("Cadastro");
    actionBar.setTitleTextColor(Color.parseColor("#846A1A"));
    setSupportActionBar(actionBar);

最佳答案

如果你不想让Toolbar随着内容滚动,那么你必须把它放在ScrollView之外。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/toolbar" />

    <ScollView
        ...>

        you content here..

    </ScollView>

</LinearLayout>

关于android - 如何将自定义 ActionBar 设置为 ScrollView 布局中的固定顶部位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29833600/

相关文章:

java - 在 WebView 在线表单中填写没有 id 的文本字段

android - 我可以添加 AnimationListener 进行 fragment 翻译吗

eclipse - 在 mac os x 上使用 J2SE 6.0 启动 eclipse 时 JVM 终止(需要 J2SE 6.0 for Oracle enterprise pack for eclipse)

c - 如何根据不同的源模块上下文突出显示公共(public)头文件?

android - Android 启动黑屏,除非使用横向

android - ConstraintLayout 半径没有响应

Android - 在LinearLayout中水平居中TextView

Android 在状态栏下绘制

java - Android:如何使用按钮背景(样式)

android - 如何设置特定于平板电脑 9.7"的布局