2012-04-25 267 views
0

在我的應用程序中,我需要用相機進行錄製。在錄製過程中,我在屏幕上顯示一些菜單項。當用戶點擊一個箭頭並在用戶觸摸屏幕時將其滑入,我需要從屏幕上滑出菜單。Android,動畫,如何從屏幕滑入和滑出佈局?

我有兩個問題。 1)看起來我的動畫不起作用。 2)當我設置RelativeLayout爲可見/不可見只是視圖生效,相機視圖不會像你在圖像中看到的那樣獲得整個屏幕(我不想看到黑色背景)。

enter image description here enter image description here

R.anim.slide_in_up:

<?xml version="1.0" encoding="utf-8"?> 

<translate 
    xmlns:android  = "http://schemas.android.com/apk/res/android" 
    android:fromYDelta = "100%p" 
    android:toYDelta = "0%p" 
    android:duration = "3000" /> 

R.anim.slide_out_up:

<?xml version="1.0" encoding="utf-8"?> 

<translate 
    xmlns:android  = "http://schemas.android.com/apk/res/android" 
    android:fromYDelta = "0%p" 
    android:toYDelta = "100%p" 
    android:duration = "3000" /> 

代碼,用於示出slide_in_up:

rlMenu = (RelativeLayout) findViewById(R.id.rlMenu); 
     imHide = (ImageView) findViewById(R.id.btn_hide); 
     imHide.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       rlMenu.setVisibility(View.INVISIBLE); 
       overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up); 
      } 
     }); 

代碼,用於顯示slide_out_up:

@Override 
    public boolean onTouchEvent(MotionEvent event) { 

     rlMenu.setVisibility(View.VISIBLE); 
     overridePendingTransition(R.anim.slide_out_up, R.anim.slide_in_up); 

     return super.onTouchEvent(event); 
    } 

屏幕布局:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
    xmlns:android   = "http://schemas.android.com/apk/res/android" 
    android:layout_width = "fill_parent" 
    android:layout_height = "fill_parent" 
    android:orientation  = "vertical" > 



    <FrameLayout 
     android:id    = "@+id/camera_preview" 
     android:layout_width = "fill_parent" 
     android:layout_height = "0dip" 
     android:layout_weight = "1" /> 



    <RelativeLayout 
     android:id    = "@+id/rlMenu" 
     android:layout_width = "fill_parent" 
     android:layout_height = "wrap_content" 
     android:orientation = "horizontal" > 

     <RelativeLayout 
      android:layout_width   = "240dip" 
      android:layout_height   = "50dip" 
      android:background    = "@drawable/btn_top_edge_right" 
      android:layout_alignParentLeft = "true" > 

      <ImageView 
       android:id      = "@+id/btn_hide" 
       android:layout_width   = "40dip" 
       android:layout_height   = "wrap_content" 
       android:src     = "@drawable/btn_record_hide" 
       android:layout_marginTop  = "10dip" 
       android:layout_marginBottom = "10dip" 
       android:contentDescription  = "@string/menu_contentdescription" 
       android:scaleType    = "fitXY" /> 

      <ImageView 
       android:id      = "@+id/btn_record" 
       android:layout_width   = "wrap_content" 
       android:layout_height   = "wrap_content" 
       android:src     = "@drawable/btn_record_start" 
       android:layout_toRightOf  = "@id/btn_hide" 
       android:layout_margin   = "10dip" 
       android:contentDescription  = "@string/menu_contentdescription" /> 

      <ImageView 
       android:id      = "@+id/btn_stop" 
       android:layout_width   = "wrap_content" 
       android:layout_height   = "wrap_content" 
       android:src     = "@drawable/btn_record_stop" 
       android:layout_toRightOf  = "@id/btn_record" 
       android:layout_marginTop  = "10dip" 
       android:layout_marginBottom = "10dip" 
       android:contentDescription  = "@string/menu_contentdescription" 
       android:clickable    = "false" />   
     </RelativeLayout> 


     <Button 
      android:id       = "@+id/btn_done" 
      android:layout_width    = "wrap_content" 
      android:layout_height    = "50dip" 
      android:background     = "@drawable/btn_record_done" 
      android:layout_alignParentRight = "true" 
      android:text      = "@string/Record_btn" 
      android:paddingLeft    = "15dip" 
      style        = "@style/simpletopic.bold" /> 

    </RelativeLayout> 
</LinearLayout> 

如何刪除整個的RelativeLayout和放大相機視圖與我的動畫? 謝謝

+0

你有沒有解決動畫的問題? – 2012-10-17 07:56:07

回答

0

對第二個問題的回答。嘗試更改您的佈局如下:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <FrameLayout 
     android:id="@+id/camera_preview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 

    <RelativeLayout 
     android:id="@+id/rlMenu" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal" > 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:orientation="horizontal" > 

      <ImageView 
       android:id="@+id/btn_hide" 
       android:layout_width="40dip" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="10dip" 
       android:layout_marginTop="10dip" 
       android:contentDescription="@string/menu_contentdescription" 
       android:scaleType="fitXY" 
       android:src="@drawable/btn_record_hide" /> 

      <ImageView 
       android:id="@+id/btn_record" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="10dip" 
       android:layout_toRightOf="@id/btn_hide" 
       android:contentDescription="@string/menu_contentdescription" 
       android:src="@drawable/btn_record_start" /> 

      <ImageView 
       android:id="@+id/btn_stop" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="10dip" 
       android:layout_marginTop="10dip" 
       android:layout_toRightOf="@id/btn_record" 
       android:clickable="false" 
       android:contentDescription="@string/menu_contentdescription" 
       android:src="@drawable/btn_record_stop" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:orientation="horizontal" > 

      <Button 
       android:id="@+id/btn_done" 
       style="@style/simpletopic.bold" 
       android:layout_width="wrap_content" 
       android:layout_height="50dip" 
       android:layout_alignParentRight="true" 
       android:background="@drawable/btn_record_done" 
       android:paddingLeft="15dip" 
       android:text="@string/Record_btn" /> 
     </LinearLayout> 
    </RelativeLayout> 

</RelativeLayout> 

我有一個類似的情況,與一個custum MapView。

+0

嗨,阿里,謝謝你。你的建議工作正常。下一步是如何應用動畫。我必須做更多的研究。再次感謝。 – Hesam 2012-04-25 06:26:41

2

我認爲這將工作,如果你使用框架佈局。添加兩個框架,並將圖片添加到框架。或者將動畫添加到兩個框架,並使其發揮作用。我認爲這將工作,並給你你想要的。一小段代碼如下所示希望這將幫助你一點點。

if (imagesetflag == true) { 
       Right_to_left_in = AnimationUtils.loadAnimation(this, 
         R.anim.right_to_left_in); 
       Right_to_left_out = AnimationUtils.loadAnimation(this, 
         R.anim.right_to_left_out); 
       left_to_Right_in = AnimationUtils.loadAnimation(this, 
         R.anim.left_to_right_in); 
       Left_to_Right_out = AnimationUtils.loadAnimation(this, 
         R.anim.left_to_right_out); 

       frame1.setImageBitmapReset(decryptedimage, 0, true); 

       frame1.bringToFront(); 
       frame1.setVisibility(View.VISIBLE); 
       frame2.setVisibility(View.INVISIBLE); 
       frame1.setAnimation(Right_to_left_in); 
       frame2.setAnimation(Right_to_left_out);          

      } else { 
       Right_to_left_in = AnimationUtils.loadAnimation(this, 
         R.anim.right_to_left_in); 
       Right_to_left_out = AnimationUtils.loadAnimation(this, 
         R.anim.right_to_left_out); 
       left_to_Right_in = AnimationUtils.loadAnimation(this, 
         R.anim.left_to_right_in); 
       Left_to_Right_out = AnimationUtils.loadAnimation(this, 
         R.anim.left_to_right_out); 

       frame2.setImageBitmapReset(decryptedimage, 0, true); 

       frame2.bringToFront(); 
       frame2.setVisibility(View.VISIBLE); 
       frame1.setVisibility(View.INVISIBLE); 
       frame2.setAnimation(Right_to_left_in); 
       frame1.setAnimation(Right_to_left_out);     

      } 
0

只要嘗試設置其他佈局元素的可見性GONE,因此主視圖將被拉伸。