2012-06-13 52 views
1

我最近一直在使用你的facebook風格的android滑塊,我想知道你是否可以幫助我。我需要使滑塊從相反的一側滑動。所以,我不需要首先從左向右滑動,而是需要從右向左移動。水平的Facebook風格的silder

你能解釋一下你是如何爲我做的?

感謝

問候, 菲利普

+0

它將有助於添加有關您正在使用哪個庫的信息。或者添加一些源代碼。 – Tim

回答

1

只要按照下面的步驟,

1)創建水平滾動型。

2)動態添加兩個視圖。

3)使用Layout Inflater爲兩個視圖充氣。

4)然後將孩子1設置爲初始視圖而不是孩子0,以便它看起來像從右向左而不是從左向右移動。

以下是關於Fb樣佈局的討論。

Layout Animation Android[Facebook]

而另外一個,

How to make Facebook's app new menu on Android?

0

你可以試試這個......

public class AnimateActivity extends Activity { 
/** Called when the activity is first created. */ 

private int oldLeft; 
private int oldTop; 
private int newBottom; 
private int newTop; 
private int screenHeight; 
private int animToPostion; 
private Display display; 
private boolean menuOpen = true; 
private AnimationListener AL; 
LinearLayout fakelayout; 
LinearLayout bottomlayout; 
Button home; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    fakelayout=(LinearLayout)findViewById(R.id.fakelayout); 
    bottomlayout=(LinearLayout)findViewById(R.id.bottomlayout); 
    home=(Button)findViewById(R.id.home); 

    display = getWindowManager().getDefaultDisplay(); 
    screenHeight = display.getHeight(); 

    int calcAnimationPosition = (screenHeight /2); 
    animToPostion = screenHeight - calcAnimationPosition;   
    newBottom = animToPostion; 
    if (menuOpen == true) { 

     RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
       RelativeLayout.LayoutParams.FILL_PARENT,animToPostion); 
     fakelayout.setLayoutParams(param); 

    } 
    home.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      if(menuOpen){ 

       animslideUp(); 
       menuOpen = false; 
      }else{ 

       animSlideDown(); 
       menuOpen = true; 
      } 
     } 
    }); 


    // Animation 

    AL = new AnimationListener() { 

     public void onAnimationEnd(Animation arg0) { 
      // TODO Auto-generated method stub 
      if (menuOpen == false) {   

       Log.i("onAnimationEnd", "menu is open now"); 
       bottomlayout.layout(0, 0, 
         bottomlayout.getMeasuredWidth(), bottomlayout.getMeasuredHeight()); 

      } else if (menuOpen == true) { 
       fakelayout.setVisibility(View.VISIBLE); 

      } 
     } 

     public void onAnimationRepeat(Animation arg0) { 
      // TODO Auto-generated method stub 

     } 

     public void onAnimationStart(Animation arg0) { 
      // TODO Auto-generated method stub 

     }}; 



} 
public void animslideUp() { 

    fakelayout.setVisibility(View.GONE); 
    Log.e("in animslideUp", "true"); 

    oldTop=bottomlayout.getTop(); 
    newTop =0; 

    Log.w("oldTop",""+oldTop); 
    Log.w("newTop",""+newTop); 

    TranslateAnimation slideUp = new TranslateAnimation(0, 0, oldTop, newTop); 
    slideUp.setDuration(500); 
    slideUp.setFillEnabled(true); 
    slideUp.setAnimationListener(AL); 
    bottomlayout.startAnimation(slideUp); 

}       

public void animSlideDown() { 



    Log.d("in animslideDown", "true"); 


    oldTop=bottomlayout.getTop(); 
    newTop = animToPostion; 
    Log.w("oldTop",""+oldTop); 
    Log.w("newTop",""+newTop); 

    TranslateAnimation slideDown = new TranslateAnimation(0, 0, oldTop,newTop); 
    slideDown.setDuration(500); 
    slideDown.setFillEnabled(true); 
    slideDown.setAnimationListener(AL); 
    bottomlayout.startAnimation(slideDown); 

} 
    } 

XML它是:

 <?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" 
        android:orientation="vertical" > 

         <LinearLayout 
         android:id="@+id/fakelayout" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:orientation="vertical" 
         android:visibility="visible" 
         </LinearLayout> 

<LinearLayout 
    android:id="@+id/bottomlayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/white" 
    android:layout_below="@+id/fakelayout" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:background="@drawable/topbar" 
     android:orientation="horizontal" 
     > 
     <Button 
      android:id="@+id/home" 
      android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/home"/> 
    </LinearLayout> 
</LinearLayout> 

    </RelativeLayout>