所以结果比我想象的要困难一点,但现在我的工作几乎正确。
这里是我结束了使用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