2011-11-15 85 views
5

我试图启动一个应用程序,我有点迷失在如何做我想要的东西。Android滑动面板

这就是我想要

left and right red sliders ; main white content

两个红色的面板应该能够滑动到边,如果他们(或两者)其中之一是折叠的白某应扩大,占据该面板空间。 当我在屏幕上显示红色面板时,白色面板显示所有内容,不在任何面板下面。

我到目前为止所尝试的是什么: 我开始时尝试了两个SlidingDrawer s,但白色面板在红色背后,所以在那里没有运气。 之后,我尝试了2 LinearLayouts(红色面板)和RelativeLayout(白色面板),并尝试用按钮更改布局的宽度(如位于顶部图像上)。这造成了我始终不知如何解决的问题。

对此提出建议?

编辑: XML的SlidingDrawer示例的:

<LinearLayout 
android:id="@+id/LinearLayout01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:gravity="bottom" 
android:background="#FFFFFFFF"> 
<SlidingDrawer 
    android:layout_width="100dip" 
    android:id="@+id/SlidingDrawer" 
    android:handle="@+id/slideHandleButton" 
    android:content="@+id/contentLayout" 

    android:layout_height="fill_parent" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:id="@+id/contentLayout" 
     android:orientation="horizontal" 

     android:background="#C0C0C0" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="Meio" 
      android:layout_toRightOf="@+id/buttonEsq" /> 
    </LinearLayout> 
    <Button 
     android:layout_width="30dip" 
     android:layout_height="30dip" 
     android:id="@+id/slideHandleButton" 
     android:background="@drawable/arrowup">   
    </Button> 
</SlidingDrawer> 
</LinearLayout> 

而的LinearLayout示例的XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 

    <RelativeLayout 
    android:id="@+id/relativeLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent"     
    android:orientation="horizontal" 
    android:layout_toLeftOf="@+id/linearLayout3" 
    android:layout_toRightOf="@+id/linearLayout1" 
    android:background="#FFFFFFFF"> 
    <Button 
     android:id="@+id/buttonEsq" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 


     android:text="v--" /> 
    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="Meio" 
     android:layout_toRightOf="@+id/buttonEsq" /> 

    <Button 
     android:id="@+id/buttonDir" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     android:layout_toRightOf="@+id/textView1" 
     android:text="--v" /> 
</RelativeLayout> 
<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="50dip" 
    android:layout_height="fill_parent" 
    android:layout_alignParentLeft="true" 


    android:background="#FFFF0000"> 
    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Esquerda" /> 
</LinearLayout> 



<LinearLayout 
    android:id="@+id/linearLayout3" 
    android:layout_width="50dip" 
    android:layout_height="fill_parent" 
    android:layout_alignParentRight="true" 



    android:background="#FFF00000"> 
    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Direita" /> 
</LinearLayout> 

</RelativeLayout> 

的机器人代码(注释的部分是第一实施例的代码) :

public class Main extends Activity { 
Button slideHandleButton; 
Button slideHandleButtonLeft; 
Button slideHandleButtonRight; 
SlidingDrawer slidingDrawer; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.mainlayouts); 
/* slideHandleButton = (Button) findViewById(R.id.slideHandleButton); 
    slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer); 

    slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() { 
     @Override 
     public void onDrawerOpened() { 
      slideHandleButton.setBackgroundResource(R.drawable.arrowdown); 
     } 
    }); 

    slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() { 
     @Override 
     public void onDrawerClosed() { 
      slideHandleButton.setBackgroundResource(R.drawable.arrowup); 
     } 
    });*/ 
    slideHandleButtonLeft = (Button) findViewById(R.id.buttonEsq); 
    slideHandleButtonLeft.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      LinearLayout lll = (LinearLayout) findViewById(R.id.linearLayout1); 
      RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(50, LinearLayout.LayoutParams.FILL_PARENT);    
      lll.setLayoutParams(params);    
     } 
    }); 
} 
} 
+0

我会发布一些你已经采取了什么方法的代码,但没有奏效。这可能会给其他人一些东西,当为你提供一种方法 – hooked82

+0

完成,希望帮助:) – Dporem

+0

[试试这个](http://androidtrainningcenter.blogspot.in/2013/06/slidingpanelayout-android-making.html ) – Sameer

回答

1

SlidingDrawer只能从右侧或底部滑入om,它无法从顶部或左侧滑入。你可以试试这个问题的答案:Android SlidingDrawer from top?或者你可以尝试重写源代码http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/widget/SlidingDrawer.java

然而,SlidingDrawer不会允许

白色面板显示的所有内容,并没有在任何面板

的,因为它会在白色面板滑出

的只有我能想到的解决方案是使用一系列比例/平移,将左侧或右侧面板平移到屏幕外并将可见性消除,同时按照任何红色面板的方向缩放中央面板祛瘀编辑。

前段时间我尝试过制作一个类似的原型,并使用这种方法,但缩放动画看起来很糟糕,更不用说onAnimationEnd侦听器不工作了,您必须扩展一个LinearLayout并覆盖onAnimationEnd。上班。

+0

检查第一句,左边提到两次。你可能意思是对的。 – 2011-11-16 14:23:35

+0

ah ooops,固定 – triggs

+0

“我能想到的唯一解决方案是使用一系列比例/平移,将左侧或右侧面板平移到屏幕外并将可见度转换为已消失,同时将中央面板放大无论哪个红色小组的方向都被删除。“ 我尝试了这种方式,并没有很好的工作...无论如何,我会提出一个不同的方法给我的老板,只是希望他喜欢它或即时通讯在疼痛的世界。无论如何,感谢您的帮助,这看起来很难回答:) – Dporem