Android系統連絡人全特效實現(下),字母錶快速滾動

來源:互聯網
上載者:User

在上一篇文章中,我和大家一起實現了類似於Android系統連絡人的分組導航和擠壓動畫功能,不過既然 文章名叫做《Android系統連絡人全特效實現》,那麼沒有快速滾動功能顯然是稱不上"全"的。 因此本篇文章我將帶領大家在上篇文章的代碼基礎上改進,加入快速滾動功能。

如果還沒有看過我 上一篇文章,請抓緊去閱讀一下 Android系統連絡人全特效實現(上),分組導航和擠壓動畫 。

其實 ListView本身是有一個快速滾動屬性的,可以通過在XML中設定 android:fastScrollEnabled="true"來啟用。包括以前老版本的Android連絡人中都是使用這種 方式來進行快速滾動的。效果如下圖所示:

不過這種快速滾動方式比較 醜陋,到後來很多手機廠商在定製自己ROM的時候都將預設快速滾動改成了類似iPhone上A-Z字母錶快速滾動 的方式。這裡我們怎麼能落後於時代的潮流呢!我們的快速滾動也要使用A-Z字母表的方式!

下面就 來開始實現,首先開啟上次的ContactsDemo工程,修改activity_main.xml布局檔案。由於我們要在介面上 加入字母表,因此我們需要一個Button,將這個Button的背景設為一張A-Z排序的圖片,然後居靠右對齊。另 外還需要一個TextView,用於在彈出式分組布局上顯示當前的分組,預設是gone掉的,只有手指在字母表上 滑動時才讓它顯示出來。修改後的布局檔案代碼如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >            <ListView        android:id="@+id/contacts_list_view"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_alignParentTop="true"        android:scrollbars="none"        android:fadingEdge="none" >      </ListView>            <LinearLayout        android:id="@+id/title_layout"        android:layout_width="fill_parent"        android:layout_height="18dip"        android:layout_alignParentTop="true"        android:background="#303030" >                <TextView            android:id="@+id/title"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center_horizontal"            android:layout_marginLeft="10dip"            android:textColor="#ffffff"            android:textSize="13sp" />      </LinearLayout>                <Button        android:id="@+id/alphabetButton"        android:layout_width="wrap_content"        android:layout_height="fill_parent"        android:layout_alignParentRight="true"        android:background="@drawable/a_z"        />                <RelativeLayout        android:id="@+id/section_toast_layout"        android:layout_width="70dip"        android:layout_height="70dip"        android:layout_centerInParent="true"        android:background="@drawable/section_toast"        android:visibility="gone"        >          <TextView            android:id="@+id/section_toast_text"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_centerInParent="true"            android:textColor="#fff"            android:textSize="30sp"            />      </RelativeLayout>        </RelativeLayout>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.