带有向上或向下箭头的Android滚动视图

时间:2013-01-28 02:55:19

标签: android xml scrollview

如果当前视图上方或当前视图下方还有更多文字,是否可以显示构成或缩小箭头的方法?在我的Android应用程序中,当前视图下面有更多文本但我希望用户知道当前视图下面还有更多文本。如何使箭头出现?

代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backgnd" >

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

              <Button
                  android:id="@+id/awesome_constant1"
                  android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
                  android:onClick="doSomething"
                  android:tag ="1"
                  android:text="@string/awesome_constant1" />
              <Button
                  android:id="@+id/awesome_constant2"
                  android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
                  android:onClick="doSomething"
                  android:tag ="2"
                  android:text="@string/awesome_constant2" />
              <Button
                  android:id="@+id/awesome_constant3"
                  android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
                  android:onClick="doSomething"
                  android:tag ="19"
                  android:text="@string/awesome_constant3" />
              <Button
                  android:id="@+id/awesome_constant4"
                  android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
                  android:onClick="doSomething"
                  android:tag ="3"
                  android:text="@string/awesome_constant4" />
              <Button
                  android:id="@+id/awesome_constant5"
                  android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
                  android:onClick="doSomething"
                  android:tag ="10"
                  android:text="@string/awesome_constant5" />
              <Button
                  android:id="@+id/awesome_constant6"
                  android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
                  android:onClick="doSomething"
                  android:tag ="7"
                  android:text="@string/awesome_constant6" />
              <Button
                  android:id="@+id/awesome_constant7"
                  android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
                  android:onClick="doSomething"
                  android:tag ="15"
                  android:text="@string/awesome_constant7" />
              <Button
                  android:id="@+id/awesome_constant8"
                  android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
                  android:onClick="doSomething"
                  android:tag ="13"
                  android:text="@string/awesome_constant8" />
              <Button
                  android:id="@+id/awesome_constant9"
                  android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
                  android:onClick="doSomething"
                  android:tag ="16"
                  android:text="@string/awesome_constant9" />
        </LinearLayout>

    </ScrollView>

</LinearLayout>

2 个答案:

答案 0 :(得分:0)

通常,解决此问题的方法是在滚动视图上设置投影或渐弱边,默认情况下应启用此选项。您可以使用XML中的android:requiresFadingEdge来设置属性。

Fading edge

如果你想要箭头,那么你必须通过添加两个图像来自己叠加它们(例如,在FrameLayout或其他东西中);没有真正内置的东西。

答案 1 :(得分:0)

您可以覆盖onScrollChanged,它可以告诉您内容是否在屏幕外 你可以在那里

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {

       View view = (View) getChildAt(getChildCount() - 1);
       int diff = (view.getBottom() - (getHeight() + getScrollY()));
       if (diff > 0) { //then not at bottom

       }
}