Android动画如果margin-top设置为负值则不起作用?

时间:2013-03-16 05:27:50

标签: android android-layout

这是我的xml布局,其中我设置了负边距顶部

<RelativeLayout 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">

   <include
     android:id="@+id/topNavBar"
     layout="@layout/top_nav_bar"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_marginTop="-80dp" />
</RelativeLayout>

这是我的Anim XML

<?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android">
 <translate android:toXDelta="0" android:fromYDelta="-80" android:toYDelta="0" android:duration="400" android:fillAfter="true" />
 <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="400" android:fillAfter="true"/>
</set>

和我的JAVA代码

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 topNavBar = (RelativeLayout)findViewById(R.id.topNavBar);
 slideDown = AnimationUtils.loadAnimation(this, R.anim.slide_down);
}

@Override
public void onClick(View v) {
 switch(v.getId()) {
   case R.id.topNavBtn:
  topNavBar.startAnimation(slideDown);
  break;
 }
}

如果值为负,我在显示导航栏时遇到问题。有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

 <rotate
        android:duration="3000"
        android:fromDegrees="0"
        android:pivotX="5%"
        android:pivotY="5%"
        android:startOffset="10"
        android:toDegrees="360" >
    </rotate>

create folder named 'anim' in resource and create set and paste this code, by using animation listener you can use animation.