gpt4 book ai didi

android - 如何在android中的 slider 内容中设置 handle 按钮?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:26:11 24 4
gpt4 key购买 nike

我正在使用 android。我用过 slider library在我的申请中。

现在我想添加一个按钮来处理幻灯片 Activity ,这样我就可以滑动内容和按钮来打开和关闭,如图所示。关闭幻灯片菜单后,按钮将出现在 Activity 的前面。

不知道可不可以。

如果您熟悉这个库,请帮助我,在此先感谢:)

enter image description here

enter image description here

我使用以下代码访问 slider 内容

       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);

最佳答案

如果您主要关心的是在 Layout 上添加图像,那么您可以做类似的事情......

步骤(1) 使用RelativeLayout 作为你的 parent 。

步骤(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中的 slider 内容中设置 handle 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23005067/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com