如何干净地叠加ScrollableViews Android中 [英] How to cleanly superpose ScrollableViews in Android

查看:215
本文介绍了如何干净地叠加ScrollableViews Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了实现一个导航栏ALA <一个href=\"http://stackoverflow.com/questions/8428416/how-to-make-facebooks-app-new-menu-on-android\">Facebook我有以下的布局的配置:

 &LT;的FrameLayout
  机器人:layout_width =match_parent
  机器人:layout_height =match_parent
&GT;
   &LT;! - 这是承载导航栏下层 - &GT;
   &LT;的LinearLayout
      机器人:layout_width =match_parent
      机器人:layout_height =match_parent
   &GT;
      &LT;! - ListView的再presenting导航栏 - &GT;
      &LT; ListView控件
       /&GT;
   &LT; / LinearLayout中&GT;   &LT;! - 这是承载内容的顶层 - &GT;
   &LT;的FrameLayout
      机器人:layout_width =match_parent
      机器人:layout_height =match_parent
   &GT;
      &LT;! - 这就是内容的视图将被注入 - &GT;
   &LT; /&的FrameLayout GT;
&LT; /&的FrameLayout GT;

所以,其基本思路是,当我想打开的导航栏的我只是转移的 TopLayer 的右边,导航栏将被揭示。
现在这个效果很好,我可以与之交互的的导航栏的的ListView ,以便通过应用程序导航,尽可能的得到里面注入的看法 TopLayer 不是 ScrollableView (如另一个的ListView ,一个滚动型的WebView )。

例如,当 TopLayer 的WebView 举例来说,我不能滚动,并与之交互的导航栏的的ListView ,因为它是的WebView 即获取滚动(althoough我把它移动到右侧)。

我想这是不平凡的叠加许多 ScrollableView 的,但我希望有黑客来克服这些问题。

感谢您的帮助!

修改

顺便说一句,这是怎么了移位 TopLayer 视图(使用的 TranslateAnimation ):

  TranslateAnimation translateAnim =新TranslateAnimation(0.0F,mListView.getWidth(),0.0F,0.0F);
translateAnim.setDuration(..);
translateAnim.setFillAfter(真);
mTopLayerView.startAnimation(translateAnim);


解决方案

原来,问题不是由于叠加 ScrollableView s或什么,但这样的事实,在使用 TranslateAnimation 逻辑位置:动画的(即不可视)视图仍然绑定到其原来的位置。因此,当我以为我点击导航的项目,我实际上与内容查看互动,我认为已经移动了。

现在我使用的<一个href=\"http://developer.android.com/reference/android/animation/ObjectAnimator.html#setPropertyName%28java.lang.String%29\"相对=nofollow> ObjectAnimator 它修正这个问题,它工作得很好。我只需要确保与pre-蜂窝设备的兼容性(我想使用 NineOldAndroids 为这件事情,如果某人知道任何其他选择来解决这个问题使用旧动画API不当,随意回答这个<一个href=\"http://stackoverflow.com/questions/10513289/android-how-to-interact-with-a-view-after-it-has-been-animated\">question).

In order to implement a navigation bar ala Facebook I have the following layout configuration:

<FrameLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
>
   <!-- This is the Lower Layer hosting the navbar -->
   <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
   >
      <!-- ListView representing the navbar -->
      <ListView 
       />
   </LinearLayout>

   <!-- This is the Top Layer hosting the Content -->
   <FrameLayout 
      android:layout_width="match_parent"
      android:layout_height="match_parent"
   > 
      <!-- This is where the View of the Content will be injected -->
   </FrameLayout>
</FrameLayout>

So the basic idea is that when I want to open the navbar I just shift the TopLayer to the right and the navbar will be revealed. Now this works well and I can interact with the navbar's ListView in order to navigate through the application, as far as the view that gets injected inside the TopLayerisn't a ScrollableView(like another ListView, a ScrollViewor a WebView).

For instance, when the TopLayeris a WebViewinstance, I can't scroll and interact with the navbar's ListViewbecause it is the WebViewthat gets scrolled (althoough I shifted it to the right).

I guess it's not trivial to superpose many ScrollableView's but I hope there are hacks to overcome these issues.

Thanks for your help!

EDIT

By the way, this is how I am shifting the TopLayerview (using TranslateAnimation):

TranslateAnimation translateAnim = new TranslateAnimation(0.0F, mListView.getWidth(), 0.0F, 0.0F);
translateAnim.setDuration(..);
translateAnim.setFillAfter(true);
mTopLayerView.startAnimation(translateAnim);

解决方案

Turns out the problem was not due to superposing ScrollableViews or anything but to the fact that when using TranslateAnimation the logical position (ie: not visual) of the animated view is still bound to its original position. Thus when I thought I was clicking on the navigation's item, I was in fact interacting with the ContentView that I thought has moved.

Now I am using ObjectAnimator which fixes this issue and it works very well. I only have to assure the compatibility with Pre-Honeycomb devices (I am thinking of using NineOldAndroids for this matter. If someones knows any other alternative to fix this properly using the old animation API, feel free to answer this question).

这篇关于如何干净地叠加ScrollableViews Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆