2012-01-13 142 views
0

我正在創建一個應用程序,我需要在畫廊中掃描圖片。我正在使用Sencha Touch。它允許我平滑地滑過圖像,但是我需要一個標題來保存我所處的圖像的數量。例如:1/5,2/5等等。在畫廊中滑動

任何想法我怎麼做在於:

我希望的代碼在JavaScript和CSS特別是。

回答

0

使用一個TextView和畫廊在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" 
    android:gravity="center_horizontal" > 

    <TextView android:id="@+id/tv" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <Gallery android:id="@+id/gal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:spacing="10px" /> 
</LinearLayout> 

在Java文件,之前onCreate()方法

TextView textView; 
Gallery gallery; 

找到的TextView如下

textView = (TextView)findViewById(R.id.tv); 
txtview.setText("1/"+count); // count is a variable which contains total no.of items in gallery 
// Initially the item in Gallery is 1st one so, i took "1/" 

接下來,如下圖片

gallery = (Gallery) findViewById(R.id.gal); 

我想你知道如何設置適配器畫廊,所以沒有解釋在這裏。

在您的活動onCreate()方法,下面寫代碼

gallery.setOnTouchListener(new View.OnTouchListener() {   
     public boolean onTouch(View v, MotionEvent event) {    
      int position = gallery.getSelectedItemPosition(); 
      txtview.setText(""+(position+1)+"/"+count); 
      return false; 
     }    
    }); 

當你刷卡廚房上面的代碼會顯示圖庫項目的位置。

 gallery.setOnItemClickListener(new OnItemClickListener() { 
      public void onItemClick(AdapterView parent, View v, int position, long id) { 
       textView .setText(""+(position+1)+"/"+count); 
      } 
     }); 

上面的代碼將顯示圖庫項目的位置,當你在廚房單擊某個項目。

我希望你能理解這一點,如果任何疑問隨時問我。

+0

我很感激。非常感謝。因爲我需要它爲Android,我會試試這個。但我在跨平臺應用程序工作,所以我更喜歡在JavaScript中的解決方案。 – Khush 2012-01-13 05:57:10

+0

也檢查新更新的答案。 – 2012-01-13 05:58:32

+0

抱歉,我不能幫你,如果你需要同樣的事情用JavaScript,怎麼我不知道的JavaScript :-) – 2012-01-13 06:01:49

0

您是否嘗試過這個庫, Jquery Touchwipe

它適用於Android

+0

好吧,我特別關注的是在JAVASCRIPT中的代碼是因爲jquery有它自己的css,並且它騎過我的css文件。另外,如果我嘗試爲IOS應用程序使用相同的代碼,則它不兼容。 – Khush 2012-01-16 04:51:16