0

如果当前视图上方或当前视图下方有更多文本,是否可以显示向上或向下箭头?在我的 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>
4

2 回答 2

1

您可以覆盖 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

       }
}
于 2013-01-28T04:06:28.047 回答
0

通常解决这个问题的方法就是在滚动视图上有一个阴影或淡入淡出的边缘,默认情况下应该启用。您可以通过android:requiresFadingEdge在 XML 中使用来设置属性。

Fading edge

If you want arrows then you will have to overlay them yourself by adding two images (for example, in a FrameLayout or something); there is nothing really built in.

于 2013-01-28T03:01:59.063 回答