2012-04-17 78 views
2

我正在编程更改framelayout内布局的边距。我的目标是制作一个像Facebook应用程序一样的滑动视图。是否有可能避免这种布局调整大小?这是我的布局移动:避免布局在保证金更改时调整大小

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:background="#00a2ff" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:id="@+id/left" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/ivGPSSearching" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="4dp" 
      android:src="@drawable/actionbar_gps_searching" /> 
    </LinearLayout> 

    <ImageView 
     android:id="@+id/ivStarsFilter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:src="@drawable/actionbar_star" /> 
</LinearLayout> 

我不希望左侧的LinearLayout被调整大小。我希望你能明白我想要什么:)

感谢

+0

你找到一个解决方案?这正是我现在面临的。 – AMTourky 2012-10-05 18:37:35

+0

也许是一个绝对的布局与setX而不是保证金窍门 – 2016-10-28 13:05:27

回答

2

实现类似我们扩展了一个Horizo​​ntalScrollView东西 - 只是覆盖onInterceptTouchEvent及的onTouchEvent总是返回false。 然后,您只需将您的菜单放在左侧,并将内容放在右侧(内容必须与屏幕宽度相匹配)。

最后设置初始Horizo​​ntalScrollView滚动并绑定到一个按钮,单击一个事件来更改滚动位置(horizo​​ntalScrollView.scrollTo或horizo​​ntalScrollView.smoothScrollTo)。

我希望这会有所帮助。

+0

感谢朱莉安娜,但我也有这个问题与其他动画。事实上,对于包含ImageView的自定义动画,ImageView在翻译过程中会缩放。你知道Android使用TranslateAnimation时如何执行动画吗? TranslateAnimation在动画过程中不缩放视图... – Jul 2012-04-17 23:03:03

1

下面是使用TranslateAnimation并设置监听器,动画和

@Override 
    public void onAnimationEnd(Animation animation) 
    { 

    //Just set the layout params for your view (layout) which is animated, 
    //to make yout view shift to the new position 

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutWidth, LayoutHeight); 

    params.leftMargin = 100; //for example you want to shift 100 px from left 

    params.rightMargin = -Layoutwidth; //this will avoid your view 
    //from shrinking and make it as wide as its width was, and - negative value will 
    //move it towards right 

    otherLayout.setLayoutParams(params); 

    } 

一个示例代码我希望它能让你的人清楚如何动画完成后,移动视图

0

我一直在过去的几个小时里,我也为此挠了挠头。 事实证明,如果你改变这两个相反的边距,ReleativeLayout内部的意见也不会被调整,也没有到处移动:

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 
lp.setMargins(0, - yOffset, Integer.MIN_VALUE, yOffset); 

这是疯了,但它的工作原理...