1

在我的Android應用的觀點是這樣的圖像:如何在android中製作這樣的動畫?

See the "D" in the image

現在,這裏d是小部件,它是任何視圖或可能已經按鈕。 我想要的是,如果用戶點擊該「D」部分,以不同顏色顯示的視圖應該被轉換爲從左到右的方式,並且只有「D」部分出現在屏幕的最右邊緣。如果用戶再次點擊該「D」部分,則視圖從右向左翻轉並看起來像上面的圖像。

如何製作?

+0

我沒有看到任何圖像:o – ingsaurabh

回答

2

此視圖被稱爲滑動抽屜。

您可以參考this滑動抽屜控制的鏈接。

有一些更多的鏈接

Link1

Link2

編輯

而且this是滑動抽屜的示範例子的鏈接

在這個演示範例有一個拉在那裏YOUT名"main.xml"有從那裏你想打開滑動抽屜

在你的情況變my:direction="topToBottom"這個描述你想從左邊滑動到右側,以便您的變量將是我:方向=「leftToRight」

+0

我已經看到該鏈接。正如我的問題所示,我想從左到右滑動。但是你的鏈接中沒有任何東西。 –

+0

請幫我從左到右滑動。 –

+0

我已經更新了我的答案。檢查 – Dharmendra

2

假設D是一個i​​mageview,它在x方向上從0移動到200。 請參閱下面的代碼。

public class DActivity extends Activity { 
ImageView D; 
int x=0,y=0; 
int a=0; 
int newx=0; 
TranslateAnimation TA; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    D=(ImageView)findViewById(R.id.d); 
    RelativeLayout RL=(RelativeLayout)findViewById(R.id.rl); 
    D.setOnTouchListener(new OnTouchListener() { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      // TODO Auto-generated method stub 
      x=v.getLeft(); 
      y=v.getTop(); 
      Toast.makeText(getApplicationContext(), "X="+x+"y="+y, Toast.LENGTH_LONG).show(); 
      if(x==0){ 
       D.setEnabled(false); 
       a=200; 
       newx=200; 
       Anim(); 
      } 
      if(x==200){ 
       D.setEnabled(false); 
       a=-200; 
       newx=0; 
       Anim(); 
      } 
      return true; 
     } 
    }); 

} 
public void Anim(){ 
    TranslateAnimation TAnimation=new TranslateAnimation(0, a, 0,0); 
    TAnimation.setInterpolator(new LinearInterpolator()); 
    TAnimation.setDuration(5000); 
    TAnimation.setFillAfter(false); 
    TAnimation.setFillEnabled(true); 
    TAnimation.setFillBefore(true); 
    D.startAnimation(TAnimation); 

    TAnimation.setAnimationListener(new AnimationListener() { 

     public void onAnimationStart(Animation animation) { } 

     public void onAnimationRepeat(Animation animation) {} 

     public void onAnimationEnd(Animation animation) {    
      LayoutParams param=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); 
      param.setMargins(newx, y, 0, 0); 
       D.setLayoutParams(param); 
       D.setEnabled(true); 
     } 
    }); 
} 

}