SlidingDrawer欠重叠在RelativeLayout的

问题描述:

我用了一个SlidingDrawer想在这个tutorialSlidingDrawer欠重叠在RelativeLayout的

它工作在一个LinearLayout中,但始终视滑块的HIGHT和所有其他的东西的空白显示空白下方。

溶剂应该使用相对布局。这会删除空格,但滑块上的处理按钮似乎在滚动视图中的内容下,并且不要通过单击它来执行任何操作。见截图 enter image description here

MainActivity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<include 
    android:id="@+id/tbar" 
    layout="@layout/primerdivisor" /> 

<SlidingDrawer 
    android:id="@+id/SlidingDrawer" 
    android:layout_width="wrap_content" 
    android:layout_height="150dp" 
    android:content="@+id/contentLayout" 
    android:handle="@+id/slideButton" 
    android:orientation="vertical" 
    android:padding="10dip" 
    android:rotation="180"> 
    <!-- Handle button --> 


    <Button 
     android:id="@+id/slideButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/button_selector" 
     android:ems="10" 
     android:rotation="180" 
     android:text="Show" android:clickable="true"/> 

    <!-- Content Layout --> 
    <LinearLayout 
     android:id="@+id/contentLayout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#FFCC" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:padding="10dip"> 

     <Button 
      android:id="@+id/Button01" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="2dp" 
      android:background="@drawable/button_selector" 
      android:text="Button 1" 
      android:textColor="@color/textBlack" /> 

     <TextView 
      android:id="@+id/text" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="2dp" 
      android:background="@drawable/button_selector" 
      android:gravity="center" 
      android:padding="5dp" 
      android:text="Text View Item" 
      android:textColor="@color/textBlack" /> 
    </LinearLayout> 
</SlidingDrawer> 

<ScrollView 
    android:id="@+id/scrollView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="10dp" 
     android:orientation="vertical"> 
.... 

MainActivity.java

... 
private void createSlider(){ 
    slideButton = (Button) findViewById(R.id.slideButton); 
    slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer); 
    b1 = (Button) findViewById(R.id.Button01); 
    textView = (TextView) findViewById(R.id.text); 

    // Setting Listeners to all buttons and textview 
    setListeners(); 

    // Listeners for sliding drawer 
    slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() { 
     @Override 
     public void onDrawerOpened() { 

      // Change button text when slider is open 
      Log.i("----","blaaaaaa open"); 
      slideButton.setText("Close"); 
     } 
    }); 

    slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() { 
     @Override 
     public void onDrawerClosed() { 

      // Change button text when slider is close 
      slideButton.setText("Open"); 
     } 
    }); 
} 

// Listeners method 
void setListeners() { 
    b1.setOnClickListener(this); 
    textView.setOnClickListener(this); 
} 

@Override 
public void onClick(View v) { 

    // Toast shown on sliding drawer items click 
    if (v.getId() == R.id.text) { 
     Toast.makeText(MainActivity.this, textView.getText() + " Clicked", 
       Toast.LENGTH_SHORT).show(); 
    } else { 
     Button b = (Button) v; 
     Toast.makeText(MainActivity.this, b.getText() + " Clicked", 
       Toast.LENGTH_SHORT).show(); 
    } 
} 
... 

滑块应该重叠滚动视图时,其whiped出

+1

将您的'SlidingDrawer'移动到其他内容的下方 – StuStirling

+0

我没想过。感谢它的工作 – WeSt

+0

我发布了一个答案,因为这个评论解决了这个问题。 – StuStirling

在视图层次而言,视图定义在你的布局XML的开始处比后面定义的“更深”。

在你的情况下,你的ScrollView被添加到你的SlidingDrawer后面的层次结构中,所以你的预期是什么。

将您的SlidingDrawer移动到您的ScrollView以下,并且应该高于此值。