2011-03-10 35 views
6

我想在android activity中添加一个面板。我会试着解释它的行为。如何在android中添加面板?

它应该在我的活动的右侧显示小箭头,如果我点击一个有少量按钮的面板应该滑出大约20%-30%的当前活动。

有点像菜单一样出现在屏幕上。

在此先感谢。

+0

[Sliding Panel](http://androidtrainningcenter.blogspot.in/2013/06/slidingpanelayout-android-making.html)和[Sliding Drawer](http://androidtrainningcenter.blogspot.in/2012/08/) android-sliding-drawer-example.html)是两个选项来寻找 – Sameer 2013-07-09 05:56:04

回答

7

查看SlidingDrawer小部件。但是,这个小部件只会在较早的SDK版本上滑动。

否则,您应该考虑使用片段(如果需要,请使用兼容性API)。您可以查找关于如何构建GMail应用程序的一些解释或者获取有关动画片段的信息的HoneyComb库示例。

+0

是的,这就是我正在寻找。 – Harshad 2011-03-10 09:53:42

+0

有没有可能修复第二个链接的机会?这就是我们现在不允许使用链接的答案的主要原因,它们很快就会过时并且不会为未来的访问者提供价值。 – 2012-03-13 08:51:57

+0

是的,网站已关闭。删除了链接并添加了一些额外的信息。 – 2012-03-13 11:44:54

0

这里是我的面板

的例子
<LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp" 
     android:background="@drawable/border"> 
     <TextView 
      android:text="@string/panel_title" 
      android:id="@+id/groupTitle" 
      android:paddingLeft="5dp" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/blue" /> 

Here you add panel content... 

</LinearLayout> 

您还需要在绘制资源broder.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
    <stroke 
     android:width="3dip" 
     android:color="#d3d3d3" /> 
</shape> 

和颜色值添加/ Colors.xml

<?xml version="1.0" encoding="utf-8" ?> 
<resources> 
    <item name="blue" type="color">#FF33B5E5</item> 
</resources> 

并在面板中标题值/ Strings.xml中

<?xml version="1.0" encoding="utf-8"?> 

<resources> 
    <string name="panel_title">Panel 1</string> 
</resources> 

至于按钮和动画,可以分开添加。