2013-11-25 70 views
0

我需要创建一个“滑动活动”,当用户滑动它时滑动。当用户向左滑动时,活动应滑动到左侧,新活动将从右侧进入屏幕。你不能把它放在中间。 Yahoo Mail应用程序也是一样的。在阅读邮件时可以看到此信息,并将邮件向左滑动以移至下一封邮件。它如下所示。将活动更改为片段,以便“滑动活动”可能

enter image description here

在图像中,可以看到下一个邮件(标题为“谢谢”)是从侧方开口。就我而言,他们是2种不同的活动。我们还可以在当前活动的右侧显示下一个活动的一小部分(如在Windows Phone中),这样用户就知道他必须滑动。无论如何,这部分现在是强制性的。

我试图用this answer来做,但它不是我所追求的。请任何想法吗?

注意

如果我去的片段,很多班级将被更改或重新完全编码。

UPDATE

请看看下面的代码。在这里,当我滑动SalesInquiry.javaNewLead.java应该打开,具有上述解释的效果。

DropDownMenu.java

import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.View.OnTouchListener; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.widget.LinearLayout; 
import android.widget.TextView; 
import android.widget.Toast; 

public class DropDownMenu extends Activity { 

    private TextView addInquiry, addEvent, additionalInfo, addToContacts; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_drop_down_menu); 

     //Intializing instance variables 
     addInquiry = (TextView)findViewById(R.id.menu_add_inquiry); 
     addEvent = (TextView)findViewById(R.id.menu_add_event); 
     additionalInfo = (TextView)findViewById(R.id.menu_additional_info); 
     addToContacts = (TextView)findViewById(R.id.menu_add_to_contacts); 

     //Register the Listeners 
     addInquiry.setOnClickListener(new AddInquiryEvent()); 


    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.drop_down_menu, menu); 
     return true; 
    } 

    //Test Button 
    private class AddInquiryEvent implements OnClickListener 
    { 

     @Override 
     public void onClick(View arg0) 
     { 
      // TODO Auto-generated method stub 
      Intent intent = new Intent(DropDownMenu.this,NewLead.class); 
      startActivity(intent); 

     } 

    } 

    public void onMenuItemClicked(View view) { 
     switch (view.getId()) { 
     case R.id.menu_add_inquiry: 
      Intent intent = new Intent(DropDownMenu.this,NewLead.class); 
      startActivity(intent); 
      break; 
     default:; 
     } 
    } 

} 

SalesInquery.java

import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.View.OnTouchListener; 
import android.view.Window; 
import android.widget.ImageView; 
import android.widget.RelativeLayout; 
import android.widget.TextView; 

public class SalesInqury extends DropDownMenu { 

    private ImageView addNewSalesInqury; 
    private RelativeLayout salesInquryMainLayout; 
    private TextView testEditSales; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_sales_inqury); 

     //Intializing instance variables 
     addNewSalesInqury = (ImageView)findViewById(R.id.add_new_sales_inqury_btn); 
     salesInquryMainLayout = (RelativeLayout)findViewById(R.id.sales_inqury_main_layout); 
     testEditSales = (TextView)findViewById(R.id.testWord); 


     //Registering Event handlers 
     addNewSalesInqury.setOnClickListener(new addNewSalesInquryEvent()); 
     salesInquryMainLayout.setOnTouchListener(mainLayoutSwiped); 
     testEditSales.setOnClickListener(new OpenSalesDemo()); //TESTING DEMO!!!!! 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.sales_inqury, menu); 
     return true; 
    } 

    //Event Handler for Add New Sales Inquery Button 
    private class addNewSalesInquryEvent implements OnClickListener 
    { 

     @Override 
     public void onClick(View v) 
     { 
      // TODO Auto-generated method stub 
      Intent intent = new Intent(SalesInqury.this,NewLead.class); 
      startActivity(intent); 

     } 

    } 

    //SWIP LISTENER 
    private OnTouchListener mainLayoutSwiped = new OnSwipeTouchListener() 
    { 
     public boolean onSwipeLeft() 
     { 
      Intent intent = new Intent(SalesInqury.this,NewLead.class); 
      startActivity(intent); 
      return true; 
     } 
    }; 


    // 
    // 
    // TESTING FUNCTION!! 
    // 
    // 
    //Testing function for sales lead opening 
    private class OpenSalesDemo implements OnClickListener 
    { 

     @Override 
     public void onClick(View arg0) 
     { 
      // TODO Auto-generated method stub 
      Intent intent = new Intent(SalesInqury.this,EditLeads.class); 
      startActivity(intent); 

     } 

    } 

} 
+0

http://stackoverflow.com/a/15879886/1939564 –

回答

0

您可以使用片段而不是活动

尝试viewpager库,请参阅

http://viewpagerindicator.com/

+0

如果我去碎片,很多类将被改变或完全重新编码。 –

+0

对不起家伙!@ᴀʀᴜnBᴇrtiL但我认为至少你是如此聪明,可以找到答案,如果它在那里。对不起@Artificial_Intelligence但我不认为有没有其他的方式来做到这一点,而不使用片段。 – keshav

3
  User GestureDetector and in onFling() method check for the direction of swipe and start the activity accordingly 

      Edited: 
    Try this: 
      GestureDetector gestureDetector = new GestureDetector(
        simpleOnGestureListener); 

     SimpleOnGestureListener simpleOnGestureListener = new SimpleOnGestureListener() { 

       // Move The Background Theme To Select The Theme 
       @Override 
       public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, 
         float velocityY) { 

        float sensitvity = 100; 

        if ((e1.getX() - e2.getX()) > sensitvity) { 

    //Move right ,start new Activity here 
return true; 
     }else if ((e2.getX() - e1.getX()) > sensitvity) { 
    //Move left ,start new Activity here 
return true; 
     }else{ 
return false ; 
} 
} 

@Override 
    public boolean onTouchEvent(MotionEvent event) { 
     // TODO Auto-generated method stub 
     return (gestureDetector.onTouchEvent(event) || super 
       .onTouchEvent(event)); 
    } 
+0

我在Google群组中也看到了rthis。你能举个例子吗? –

0

您可以直接使用片段精确SupportFragment和ViewPager,让你通过不同的fragements刷卡。它在android.support.v4库中可用。

+0

如果我使用片段,很多类将被更改或完全重新编码。 –

+0

然后我必须看看你的代码,因为那样我才能知道要做什么。 – VishalKale

+0

请参阅编辑 –