2012-03-17 206 views
28

任何人都知道的Android的幻燈片切換的任何開源實現。默認的Android切換(ToggleButton)並不漂亮。我正在尋找類似於iOS的任何東西。我應該可以從頭開始實施。但如果任何類似的東西已經可用,那麼我可以建立它。幻燈片切換爲Android

在此先感謝美妙的計算器社區。

EDIT1: 我的意思通過iOS的幻燈片切換是UISwitch

ios Toggle Button



EDIT2:只想總結答案。 Commonsware提供了線索。我結束了將開關的代碼從4.0移植到了2.2.2。由於開源代碼,後端移植並不是非常困難。代碼託管在git集線器上。 http://github.com/pellucide/Android-Switch-Demo-pre-4.0/tree/master/

從該項目
Screen shot

+3

我結束了背移植4.0代碼到2.2.2。我還爲小部件添加了一些新的屬性,以適應我正在開發的項目。雖然外觀與iOS或Android不完全相同,但可以使用drawable輕鬆更改。該項目託管在github上 https://github.com/pellucide/Android-Switch-Demo-pre-4.0/tree/master/android-switch-demo – pellucide 2012-05-30 09:40:31

+0

對不起,我之前沒有看到這個,因爲我只是做了同樣的事情:我支持Switch類與2.2一起工作。結果在這裏:https://github.com/BoD/android-switch-backport - 我希望它可以是有用的,它與你自己的端口稍有不同,因爲它包含了ICS的'標準'drawables。 – BoD 2012-06-12 01:16:17

+0

哇!做得好。我也希望在剝皮按鈕之前看到了這一點。 http://stackoverflow.com/questions/9920709/use-android-4-0-styled-toggle-button/15640365#15640365 – dberm22 2013-03-26 17:08:05

回答

13

iOS似乎沒有「滑動切換」,至少在該名稱的基礎上,谷歌搜索。而且,你沒有提供你想要的圖像(或圖像的鏈接)。

Android 4.0添加了Switch,您可能可以將其恢復到早期版本。你會看到它的樣本在你的模擬器的API演示應用程序:

enter image description here

+0

這很接近。我將不得不支持切換代碼。謝謝 ! – pellucide 2012-03-19 20:32:05

+1

你是如何移植它的? – 2013-08-20 13:15:18

1

的屏幕截圖您可以嘗試使用ToggleButton指定自己的可繪其狀態。

+1

這可以工作。但我正在尋找從一個州到另一個州的滑動運動。它給人一種切換開關的感覺。 – pellucide 2012-03-22 17:21:52

+1

ToggleButtons沒有** sliding **效果** – 2014-03-26 09:25:23

15

可以使用滑動抽屜部件在android系統有一個滑動切換開關。您只需將ios切換圖像「切片」爲3個部分,一個用於手柄,一個用於滑動抽屜背景,另一個用於內容部分。然後把圖像放在它的上面像一個框架給你「圓緣」

這裏就是我想出了: XML佈局

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
    <FrameLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="100dp" > 
     <SlidingDrawer 
      android:id="@+id/slidingDrawer1" 
      android:layout_width="154dp" 
      android:layout_height="54dp" 
      android:background="@drawable/ios_retina_toggle_on_full" 
      android:content="@+id/content" 
      android:handle="@+id/handle" 
      android:orientation="horizontal" > 
      <ImageButton 
       android:id="@+id/handle" 
       android:layout_width="54dp" 
       android:layout_height="54dp" 
       android:background="#00000000" 
       android:src="@drawable/ios_retina_toggle_button" /> 
      <ImageView 
       android:id="@+id/content" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ios_retina_toggle_off" /> 
     </SlidingDrawer> 
     <ImageView 
      android:id="@+id/imageView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ios_retina_toggle_frame" /> 
    </FrameLayout> 
</LinearLayout> 

ios_retina_toggle_on_full
ios_retina_toggle_on_full.png

ios_retina_toggle_button
ios_retina_toggle_button.png

ios_retina_toggle_off
ios_retina_toggle_off.png

ios_retina_toggle_frame
ios_retina_toggle_frame.png

最後一個它是如何看在模擬器上3截圖。7 WVGA屏幕運行薑餅: enter image description here

+0

這是一個聰明的做法。我今天會嘗試。不過,我已經從Android 4.0「開關」的代碼,並適應它在Android 2.2.x上工作。我設法添加了一些額外的功能,如textOnButton和textOutside。 textOnButton-除了在軌道上的文字按鈕(圓)。 textOutside - 將文本置於軌道之外。 – pellucide 2012-04-03 17:15:51

+0

你能提供一個例子或來源嗎?這將是非常有用的,因爲我試圖做同樣的.. – neteinstein 2012-05-02 17:01:33

+0

@NeTeInStEiN你只需要這個xml佈局的工作,加上我已經提供的切片圖像。那麼它只是一個滑動drawer類,如果值爲true,則可以將其isOpened()方法用作「On」狀態。 – vinceville 2012-05-14 08:45:16

1

我們可以嘗試使用自定義繪製資源和拇指搜索條,最大值設置爲1和最小爲0,我們可以添加動畫的滑動效果