2014-12-13 71 views
1

我有一个基本上是一个listview和一个按钮的relativelayout。我的列表视图在宽度和高度上设置为"match_parent"。我的按钮显示在屏幕底部layout_alignParentBottom = "true";ListView中的动画视图

我想达到谷歌浏览器与其网址栏类似的效果。我的意思是,我希望能够在向下滚动时使按钮不可见,并在滚动时可见,就像Chrome一样。

我试着重写onScroll()方法的列表视图和使用TranslateAnimation()但我无法得到我正在寻找的效果。

在此先感谢

回答

0

可以使用FloatingActionButton库机器人。
在XML中使用它:

<ListView 
     android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

<com.melnykov.fab.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|right" 
     android:layout_margin="16dp" 
     android:src="@drawable/ic_action_content_new" 
     fab:fab_colorNormal="@color/primary" 
     fab:fab_colorPressed="@color/primary_pressed" 
     fab:fab_colorRipple="@color/ripple" /> 

然后将其连接到您的ListView:

ListView listView = (ListView) findViewById(android.R.id.list); 
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
fab.attachToListView(listView); 
+0

不完全是我正在寻找...但无论如何。希望有人现在可以说我的意思。 – fapps 2014-12-13 22:14:20

+0

Android浮动操作按钮,对滚动事件作出反应。当连接的目标向上滚动时变为可见,向下滚动时不可见。 - 这不是你想要的吗? – 2014-12-14 06:00:06

+0

是的,但不是确切的方式,我的意思是,我想要一个带有文字和Holo风格的按钮,因为我没有升级到Material Design,我不喜欢混合风格... – fapps 2014-12-14 08:25:24

0

您需要设置的ListView滚动监听器,并写出滚动方法在it.Like隐藏按钮,而listview向上滚动。但是你不能直接在listview上实现TranslteAnimation,而FileAfter是true,它会导致一个复杂的问题。