一、什麼是Android抽屜
Android抽屜是指在Android應用程序中的一種UI設計風格,它通過可滑動的側邊欄來提供導航欄、菜單等功能。抽屜通常在應用程序的主界面上呈現一個圖標,用戶可以通過拖動或點擊該圖標在主界面和側邊欄之間進行切換。它的出現讓用戶能夠很方便的進行導航、查看用戶資料、搜索等操作,增強了用戶體驗感和應用程序的交互性。
二、為什麼選擇Android抽屜
1、提升用戶體驗:抽屜菜單方便用戶更快速的導航和使用應用程序,避免了翻頁或者切換tab導致的信息要重新讀取頁面的問題。
2、方便快捷:抽屜菜單更易於訪問單獨功能模塊,用戶通過抽屜途徑,一步進入關心的功能,這樣在大大提高了操作效率的同時也給用戶帶來了使用愉悅感。
3、承載更多信息:抽屜中可以嵌套分類和子菜單,不同的應用可以實現不同的目的,抽屜還可以被程序用做信息提示的承載平台。
三、如何實現Android抽屜
1、首先需要在布局文件中設置側滑欄、Activity的顯示內容、ToolBar並在側滑欄和Activity中添加一些菜單選項。
<android.support.v4.widget.DrawerLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/drawer_layout"> <!-- 主界面內容 --> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 設置ToolBar --> <android.support.v7.widget.Toolbar android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary"/> <!-- 設置主界面布局 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!"/> </RelativeLayout> <!-- 抽屜菜單欄 --> <LinearLayout android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="@android:color/white" android:orientation="vertical"> <!-- 添加菜單選項 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="選項1" android:padding="16dp"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="選項2" android:padding="16dp"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="選項3" android:padding="16dp"/> </LinearLayout> </android.support.v4.widget.DrawerLayout>
2、在Activity中聲明ActionBarDrawerToggle並設置DrawerLayout監聽器,處理DrawerLayout的開和關。
public class MainActivity extends AppCompatActivity { private DrawerLayout mDrawerLayout; private ActionBarDrawerToggle mDrawerToggle; protected void onCreate(Bundle savedInstanceState) { mDrawerLayout = findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.open_drawer, R.string.close_drawer); mDrawerToggle.syncState(); mDrawerLayout.addDrawerListener(mDrawerToggle); } }
3、最後在menu文件夾(如果沒有,需要新建一個)中添加菜單選項,設置圖標和文本即可。
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/action_settings" android:title="@string/action_settings" android:icon="@drawable/ic_settings_black_24dp"/> <item android:id="@+id/action_help" android:title="@string/action_help" android:icon="@drawable/ic_help_outline_black_24dp" /> </menu>
四、Android抽屜的使用場景
1、針對大型APP:例如新聞、購物類的APP,側滑欄可以更好地顯示分類、資訊、排行榜、個人中心等信息,並且方便用戶進行篩選,從而帶來更好的用戶體驗。
2、針對地圖類APP:在地圖中嵌入抽屜菜單可以非常方便地提供路線規劃、路況查詢、周邊POI查找等操作,並且抽屜中的切換可以不會影響主界面,避免地圖重新載入帶來的耗時操作。
3、針對側滑欄信息推送:通過推送系統向用戶發送的信息,例如關注的公眾號文章推送,都可以通過側滑欄進行展示,不影響APP主界面的操作,同時也起到一個很好的提示作用。
五、總結
Android抽屜給用戶操作提供了一種更方便的方式,不僅僅方便了用戶的使用體驗,同時也為APP提供了更多的可擴展性,這在當前App佔據了大頭市場的時代尤為重要。但是需要注意,為了保持交互的簡潔性,業務需求合理性等,單個側邊欄不宜設置過多的功能項,同時需要細心把握側邊欄和主界面的UI設計風格,畢竟抽屜顯示出來的是設計的品味和質量。在應用開發時,根據不同需求和特點合理運用抽屜,可以給用戶帶來比較好的使用體驗,從而提高應用的參與度和用戶黏性。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/239401.html