Android在同一活动中扩展了两个类

时间:2015-03-18 17:33:56

标签: android android-activity android-maps-v2 android-sliding

在我的Android应用程序中,我需要滑块菜单导航(如Facebook)并在同一活动中进行映射。对于滑块菜单,我有一个代码,主类扩展SlidingFragmentActivity,映射我扩展FragmentActivity。我的问题是如何使用滑动菜单和地图扩展同一活动中的两个类。

3 个答案:

答案 0 :(得分:1)

我通过扩展课程解决了我的问题。

class SliderMenuActivity extends FragmentActivity{

....
}

MyClass extends SliderMenuActivity {
 ......
}

现在MyClassFragmentActivity

的子类

谢谢大家。

答案 1 :(得分:0)

由于java不支持多重继承,因此无法通过单个类扩展多个类。

为了实现目标,您可以做一些与众不同的事情。 您可以使用父活动。在该活动的内部,您可以为2个不同的目的定义2个不同的片段。

public class JoblistFragment extends Fragment implements OnScrollListener {
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             final Bundle savedInstanceState) {

             .....
             return rootView;
        }
        public static class PlaceholderFragment extends Fragment {
                public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
                      .........
                      ....

                }

        }

}

答案 2 :(得分:0)

"滑块菜单导航(如Facebook)"你指的是,实际上是NavigationDrawer。官方文档描述了如何以完整的细节实现它。你可以找到它here

总之,您将在xml中创建一个布局,如下所示

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>
</android.support.v4.widget.DrawerLayout>

此外,您的活动中需要进行设置(请参阅提供的链接以获取完整参考)。最终结果如下图所示。

打开:

Open

闭:

Closed