2013-01-16 44 views
0

我創建了一個安卓滑動抽屜,但是當它被解散時,它完全隱藏。我正在尋找的行爲是讓抽屜的第一行始終可見。如果這是可能的,最好的嘗試方法是什麼?安卓滑動抽屜第一排始終可見

回答

0

這個工作對我來說:

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

    <Button 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:text="Button 1" /> 

    <SlidingDrawer 
     android:id="@+id/slidingDrawer1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/button1" 
     android:content="@+id/content" 
     android:handle="@+id/handle" > 

     <Button 
      android:id="@+id/handle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Handle" /> 

     <ScrollView 
      android:id="@+id/content" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 

      <LinearLayout 
       android:id="@+id/content1" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:scrollbars="vertical" > 

       <Button 
        android:id="@+id/button1a" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Button 1" /> 

       <Button 
        android:id="@+id/button2" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Button 2" /> 
      </LinearLayout> 
     </ScrollView> 
    </SlidingDrawer> 

</RelativeLayout> 

而且在主要活動:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    actionsSlider = (SlidingDrawer) findViewById(R.id.slidingDrawer1); 
    actionsSlider.setOnDrawerCloseListener(new OnDrawerCloseListener() { 
     public void onDrawerClosed() { 
      firstButton = (Button) findViewById(R.id.button1); 
      firstButton.setVisibility(View.VISIBLE); 

     } 
    }); 

    actionsSlider.setOnDrawerScrollListener(new OnDrawerScrollListener() { 

     public void onScrollStarted() { 
      if (!actionsSlider.isOpened()) { 
       findViewById(R.id.button1).setVisibility(View.GONE); 
       firstButton = (Button) findViewById(R.id.button1a); 
      } 
     } 

     @Override 
     public void onScrollEnded() { 
     } 
    }); 
}