0
我是相當新的android開發,我有一個很難搞清楚創建可重用的代碼最簡單的方法。我在google上發現了不少文章,android有許多零件和解決方案,我無法看到優點和缺點,所以我只會發布我想要做的事情,然後看看彈出的內容。創建與其他小部件自定義部件包括
目前我有:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar"
layout="@layout/widget_toolbar"/>
<ListView
android:background="@color/amber_A700"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar">
</ListView>
</RelativeLayout>
<apps.new.app.ui.widget.ScrimInsetsFrameLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/linearLayout"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ffffffff"
android:fitsSystemWindows="true"
app:insetForeground="#4000" >
<fragment android:id="@+id/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.newapp.NavigationDrawerFragment"
tools:layout="@layout/frag_nav_drawer" />
</apps.new.app.ui.widget.ScrimInsetsFrameLayout>
</android.support.v4.widget.DrawerLayout>
基本上我想要的是讓這個在我可以在任何項目中,我想用一個更簡潔的風格使用庫:
<android.my.custom.widget
...
app:drawerFragment="drawer_fragment_name"
...>
//Listview would go here
</android.my.custom.widget>
這允許我設置抽屜碎片,自動包含「ScrimInsetsFrameLayout」,自動包含工具欄。基本上我想要一個可重用的庫,我可以更新它,並將它推送到我使用它的任何應用程序中。使用android dev的最佳做法是什麼?如果這只是一個自定義小部件,我將如何去包含其他小部件並在其中插入片段?
最終這將讓我簡化代碼一堆只看到究竟是什麼活動,而不是看到一堆的鍋爐板代碼爲抽屜式導航的RelativeLayout和工具欄。
我覺得我只是缺少一些明顯的東西。