【问题标题】:i have some views within a scrollview.i want to change the title of the actionbar while scrolling up我在滚动视图中有一些视图。我想在向上滚动时更改操作栏的标题
【发布时间】:2015-03-16 10:03:42
【问题描述】:

我在 xml 文件的滚动视图中有一些视图。我想在向上滚动时更改操作栏的标题。请帮助我如何做到这一点..

这是我的 xml 文件

<ScrollView 
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <LinearLayout 
        android:layout_width="wrap_content"
        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="name"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="email"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="address"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>
    </ScrollView>

【问题讨论】:

  • 滚动更改时使用 onscrollchnage 和更新标题

标签: android android-actionbar


【解决方案1】:

你想观察滚动视图的滚动吗?无论出于何种原因,您不能通过 Android SDK 为滚动视图执行此操作(但您可以为列表视图)。结果有整个图书馆!

https://github.com/ksoichiro/Android-ObservableScrollView

或者你可以很容易地实现类似的东西,比如 https://stackoverflow.com/a/3952629/3865761 如果满足您的需求。站在堆栈溢出巨人的肩膀上。

一旦您可以检测到滚动,只需使用诸如 onScrollUp() 之类的方法来增加您的 textview 的字体大小,并使用 resetTextViewState() 将其设置为从您实现的 onScrollingChanged() 回调调用的默认值。

【讨论】:

  • 但我没有列表视图。我只是为我的个人资料页面设计这个 xml 文件。我想在向上滚动时,人名应该出现在操作栏中。所以可以我使用这个库github.com/ksoichiro/Android-ObservableScrollView
  • 但我没有列表视图。我仅为我的个人资料页面设计此 xml 文件。我想在向上滚动时,此人的姓名应出现在操作栏中
  • 您可以免费使用该库,只需检查许可证即可。尽管该库可能有点过分,但如果您检查我发布的堆栈溢出链接,它包含一些用于设置简单回调的示例代码,该回调将告诉您滚动视图何时以及如何滚动。此时,根据传递的参数,您可以在操作栏中隐藏/显示此人。
  • 如何在 androd 中设计一个活动,如 truecaller 应用程序(5.22 版)我的个人资料页面。
  • 你必须通过监听滚动发生时触发的回调来实现你想要的效果。即,如果您想更改操作栏中标题文本的大小,您将首先设置从滚动视图到 Activity 的“onScrolled”回调,然后根据滚动量或位置计算文本的大小,然后更改文本视图的大小。或者您可以找到一个库来为您执行此操作,例如 android-arsenal.com/details/1/1577
猜你喜欢
  • 1970-01-01
  • 2020-12-21
  • 1970-01-01
  • 1970-01-01
  • 2013-08-14
  • 1970-01-01
  • 2014-01-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多