2013-03-16 50 views
2

這裏是我的XML佈局,其中我設定的陰性切緣頂部Android動畫如果margin-top設置爲負值,它不起作用?

<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; 
} 
} 

我有顯示問題導航欄如果值爲負數。有人能幫助我嗎?

+0

爲什麼要這麼做?爲什麼你使用負值? – 2013-03-16 06:21:52

回答

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. 
相關問題