2

这是我将负边距设置为顶部的 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>

这是我的动画 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;
 }
}

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

4

1 回答 1

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.
于 2013-03-16T09:09:16.150 回答