[閒聊] listview一次只移動1 Item的方法
最近在做listview一次只移動 1 item
也就是不會滑過頭的方法
我看了許多文章但還是覺得很複雜..
於是就自己寫了一個
不過看了一下感覺好像更複雜...
///開控制時鐘讓一次不會滑兩格
Timer timer = new Timer(true);
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
timer.schedule(new timerTask(), 1000, 1000);
}
public class timerTask extends TimerTask
{
public void run()
{
locked2=1;
}
};
///最新帳單控制
list_new.smoothScrollToPosition(0);
list_new.setAdapter( new SimpleAdapter(
getActivity(),list2,
R.layout.my_list_layout_fg,
new String[] { "start_pag","Status","newinfo"},
new int[] { R.id.my_list_start_iv, R.id.check_pay_tv,
R.id.info_tv_mylist } ){
int fastmove=0;
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView==null){
convertView=View.inflate(getActivity(),
R.layout.my_list_layout_fg, null);
}
///起始位置
if(fastmove==0){
move=0;
list_new.smoothScrollToPosition(move);
fastmove=1;
}
//確定只移動一次
if(locked2==1){
///確定只一次只移動一格
if(Math.abs(move-position)==1){
list_new.smoothScrollToPosition(position);
move=position;
locked2=0;
}else{
if(move-position>0){
move=move-1;
list_new.smoothScrollToPosition(move);
}else if(move-position<0){
move=move+1;
list_new.smoothScrollToPosition(move);
}
locked2=0;
}
}else{
list_new.smoothScrollToPosition(move);
}
list_new.smoothScrollBy(0, 0);
return super.getView(position, convertView, parent);
}
});
有沒有鄉民有好方法呢...
感覺我好像犯蠢了LOL?
想要實驗的效果
必須用使用Fragment
listview與viewpager都可以正常滑動
而且listview一次只能移動1 item..
我的作法:
再把listview套到Vector裡面再套到viewpager裡面
而且listview能夠像viewpager一樣一次只動一格
用計時器控制listview在1秒內的移動格數
有沒有鄉民能分享比較快的方法還是有什麼建議呢?
--
□卑怯戦隊□ __ _ ▍▍▎▎▏▏ψquetzal ◤ ◥ ◢ ◥
▇▇▇ ▇▇▇ ▇▇▇▇ █ ▇▇▇│▏ ◤ ◢◢▼ ◢ ◤◥ █ █
▇▇▇ ◤ ◤ ▉▇▇ ▁ ◣ ▉▇▇ __◤★ ★ ____◤◥◥ ﹣ —▼ █ █
█ ▁▁█ ▉ ◤ █ ▉ ◤ ↖◣ ■ ◢ 《ξ● ● ◣▼'"◢◤██
█ █ ▉ ◢ █ ▉ ◢ ▃▃◥██◣ ﹨◣︶;"◢◤◢ ▊▎██
▇▇ ◤ █▇ ◤▼▼ ▇ ▲▲▼▼ ▇◣◢◤★ ★ ◥ ﹨◤▆ ◥◆︶▲■▅ ▅
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.34.164.154
※ 編輯: tga123 來自: 114.34.164.154 (01/07 17:18)
→
01/07 17:27, , 1F
01/07 17:27, 1F
→
01/07 17:30, , 2F
01/07 17:30, 2F
→
01/07 17:33, , 3F
01/07 17:33, 3F
→
01/07 17:34, , 4F
01/07 17:34, 4F
我要做個帳單整理的APP
左右移動來區分不同月份帳單
上下移動來看該月每日的帳單
至於一筆一筆看是因為怕一次滑太快會漏看
一個畫面顯示一個完整的Item就可以了
另外補充一下所有Item的大小都是固定的
感謝鄉民提供orz我回去再詳讀一下~
※ 編輯: tga123 來自: 114.34.164.154 (01/07 18:20)
→
01/09 09:22, , 5F
01/09 09:22, 5F
→
01/09 10:56, , 6F
01/09 10:56, 6F