所以結果比我想象的要困難一點,但現在我的工作幾乎正確。
這裏是我結束了使用OnTouchListener:
listOnTouchListener = new OnTouchListener() {
public boolean onTouch(View v, MotionEvent me){
if (me.getAction() == MotionEvent.ACTION_DOWN){
//This means a finger has come down on top of our view
//We are going to start the animation now.
Log.i(myTag, "Action Down");
Context mContext = getApplicationContext();
Resources res = mContext.getResources();
TransitionDrawable transition = (TransitionDrawable) res.getDrawable(R.drawable.listtransition);
v.setBackgroundDrawable(transition);
//LongClick took approx. 510-530 milliseconds to register after OnTouch. So I set the duration at 500 millis.
transition.startTransition(500);
}else if (me.getAction() == MotionEvent.ACTION_UP){
//This means we didn't hold long enough to get a LongClick
//Set the background back to the normal one.
v.setBackgroundResource(R.drawable.bubblelight);
}else if (me.getAction() == MotionEvent.ACTION_MOVE){
//Do Nothing
}else if (me.getAction() == MotionEvent.ACTION_CANCEL){
Log.i(myTag, "Action Cancel");
//This means we are scrolling on the list, not trying to longpress
//So set the background back to the normal one.
v.setBackgroundResource(R.drawable.bubblelight);
}
return false;
}
};
我還使用了OnLongClickListener這裏面我設置的背景回到正常的一個。
這裏是轉變XML:
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bubblelight1" />
<item android:drawable="@drawable/bubbledark" />
</transition>
你可能會問與bubblelight1什麼?更多關於這一點。
這是我用我的轉接器內返回該得到顯示在列表視圖的getView()方法:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
Status s = items.get(position);
if (s != null) {
v.setOnTouchListener(listOnTouchListener);
v.setOnLongClickListener(listOnLongClickListener);
tweetTxt = (TextView) v.findViewById(R.id.tweetTxt);
timeTxt = (TextView) v.findViewById(R.id.timeTxt);
if (tweetTxt != null) {
tweetTxt.setText(s.getText());
tweetTxt.setOnTouchListener(gestureListener);
}
if(timeTxt != null){
timeTxt.setText(getTimeFromNow(s.getCreatedAt().getTime()));
//timeTxt.setText(s.getCreatedAt().toLocaleString());
}
}
LinkifyWithTwitter.addLinks(tweetTxt, Linkify.ALL);
return v;
}
v.setOnTouchListener(listOnTouchListener);和 v.setOnLongClickListener(listOnLongClickListener);是與上面顯示的聽衆一起設置視圖的線條。
現在關於bubblelight1。泡泡燈和泡泡堂是我在第一次嘗試這個過程時使用的9個補丁圖像,而不是從泡泡燈到泡泡堂的過渡,泡泡燈會變得更大,泡泡燈會出現在泡泡燈內。所以我有一個很大的泡沫,很小,泡沫很暗,然後是裏面的文字。爲了解決這個問題,我製作了一個bubblelight的副本,並且使得ninepatch的底部和右側邊緣完全被填充。我只需要在轉換過程中完成第一個圖像,而不是第二個。如果我這樣做了第二張圖像,那麼我的文字就會從泡泡中跳出來,有些則會在泡泡的頂部和兩側顯示出來。我不完全確定爲什麼會發生這種情況,或者爲什麼這種修復方法發生了工作。但它現在完成這項工作。
這樣做http://stackoverflow.com/questions/6513301/android-how-to-achieve-the-glow-effect-when-的簡單方法long-pressing-a-list-item – Sabre 2014-09-22 00:00:40