我正在使用android.I在我的应用程序中使用slider library。
现在,我想添加一个按钮来处理幻灯片 Activity ,因此我可以与按钮一起滑动内容以打开和关闭图片,如图中所示。关闭幻灯片菜单后,按钮将出现在 Activity 的前面。
不知道有没有可能
如果您熟悉此库,请帮助我,在此先感谢:)
我使用以下代码访问滑块内容
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setApp_id("ads");
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setSecondaryMenu(R.layout.slide);
最佳答案
如果您主要关心的是在布局上添加图像,那么您可以做一些类似的事情..
步骤 (1) 使用 RelativeLayout
作为您的父级。
步骤(2)对于您的 ImageView ,请像这样使用..
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/content_frame"
android:layout_alignParentTop="@+id/content_frame"
android:layout_centerInParent="true"
android:src="@drawable/slider" />
步骤(3)现在在你的java类中获取这个 ImageView 的id并将setOnClickListener放入它。
现在点击只需将您定义的代码关闭和打开。确保检查抽屉打开然后关闭抽屉,如果抽屉关闭则打开抽屉。
除此之外,我建议你使用 ActionBar NavigationDrawer 来做同样的事情.. 使用起来非常方便。
我在我的一个项目中使用 Navigation Drawer 执行了相同的操作。
希望能帮助到你..
编辑
如果您使用的是 ActionBar NavigationDrawer 或其他任何东西,那么您的首选布局应如下所示..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</FrameLayout>
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/content_frame"
android:layout_alignParentTop="@+id/content_frame"
android:layout_centerInParent="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
<ListView
android:id="@+id/listview_drawer_two"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@color/taxi_list_light"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="2dp" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
只需将此布局复制并粘贴到新的 XML 文件中.. 看看它看起来如何..
更多关于这个我会建议你看看这个教程.. http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
希望能帮助到你!
关于android - 如何在android的滑块内容中设置 handle 按钮?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23005067/