Groups
Sign in
Groups
日本Androidの会
Conversations
About
Send feedback
Help
ScrollViewの移動による画像の表示切替について
576 views
Skip to first unread message
H.Kunimoto
unread,
Apr 20, 2011, 10:43:14 AM
4/20/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 日本Androidの会
初めまして。地方でandroid開発を行っているkunimotoと申します。
早速ですがご質問をいたします。
現在、ScrollViewを使ったアプリを開発しておりまして
ScrollViewがこれ以上移動できなくなった際に
表示されている画像を非表示にしたいのですが、なかなかうまくいきません。
■仕様について
具体的に申しますと
レイアウトの構成は以下のようになっております。
01 <ImageView />
02 <ScrollView>
03 <RelativeLayout>
04 省略(ImageViewが複数縦に並んでいます)
05 </RelativeLayout>
06 </ScrollView>
07 <ImageView />
仕様を説明しますと、
[1]まずこの画面を一番最初に表示させた場合
01行目のImageViewは非表示
07行目のImageViewは表示
といった状態になります。
[2]最初の状態からScrollViewを上向きに移動させると
非表示の01行目のImageViewが表示されるようになります。
(07行目は表示されています)
[3]そしてScrollViewがこれ以上上に移動できなくなった時
07行目のImageViewを非表示にします。
(01行目は表示されています)
[4]逆方向も同じで
ScrollViewをこれ以上下に移動できなくなった時
01行目のImageViewを非表示にします。
(07行目は表示されています)
■問題について
画面を単純に指でスライドさせて
これ以上移動できなくなった場合は仕様通りに動くのですが
フリック操作(リストをスクロールする時に指で軽くはらう操作
ここでは04行目に記述した縦に並んでいる画像を指ではらっている)を行った際に
ScrollViewがこれ以上動かなくなった場合でも、画像が非表示になりません。
(上記[3]および[4]が正しく動作しません)
■ソースなどの各種情報について
処理としてはOnGestureListenerを実装し
フリック操作が行われた時に以下のように処理を行っております。
public boolean onFling(MotionEvent e1, MotionEvent e2, float
velocityX, float velocityY) {
//ScrollViewのY座標が0→下方向に動かない場合は
//画像を非表示にする
if(thirdScroll.getScrollY() <= 0){
topArrow.setVisibility(View.INVISIBLE);
topVisible = false;
}else{
topArrow.setVisibility(View.VISIBLE);
topVisible = true;
}
//ScrollViewが一番下まで到達し
//これ以上上方向に動かない場合は画像を非表示にする
if(thirdScroll.getScrollY() >= thirdLayoutMain.getHeight() -
thirdScroll.getHeight()){
bottomArrow.setVisibility(View.INVISIBLE);
bottomVisible = false;
}else{
bottomArrow.setVisibility(View.VISIBLE);
bottomVisible = true;
}
return false;
}
また開発および検証については以下の環境で行っております。
実機:日本通信IDEOS Android2.2.1
エミュレータ:Android2.1並びにAndroid2.2
OS:Windows 7 Home Premium(64bit)
開発環境:eclipse 3.6 pleiades ultimate
Developerドキュメントや海外サイトの情報など
各種リファレンスを用いて調査しましたが
解決の気配が見えてきません(調査不足の可能性もあるかもしれませんが・・・)。
よろしければ、お力を貸していただけたらと思います。
以上、よろしくお願いいたします。
大垣憲俊
unread,
May 29, 2011, 12:27:45 PM
5/29/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to android-g...@googlegroups.com
大垣です。
VelocityTrackerを使うのが良いのではないでしょうか。
Launcher2のWorkspace.javaのonTouchEvent()あたり、参考になるでしょうか。
http://android.git.kernel.org/?p=platform/packages/apps/Launcher2.git;a=blob;f=src/com/android/launcher2/Workspace.java;h=c337c3078eed48bbdffbbefaac391610300962f0;hb=refs/heads/froyo
Katsunori Gotoh
unread,
May 29, 2011, 12:54:39 PM
5/29/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 日本Androidの会
五嶋と申します。
ScrillViewよりもListViewにした方が制御が簡単かもしれません。
Reply all
Reply to author
Forward
0 new messages