我想实现一个滑动手势来删除ListView类似于android通知的行.
现在我只有一个ListView有onTouchListener-这么说,我已经有刷卡的检测工作.
gestureDetector = new GestureDetector(this, new GestureListener());
onTouchListener = new TouchListener();
listview.setOnTouchListener(onTouchListener);
Run Code Online (Sandbox Code Playgroud)
我的GestureListener班级:
protected class GestureListener extends SimpleOnGestureListener
{
private static final int SWIPE_MIN_DISTANCE = 150;
private static final int SWIPE_MAX_OFF_PATH = 100;
private static final int SWIPE_THRESHOLD_VELOCITY = 100;
private MotionEvent mLastOnDownEvent = null;
@Override
public boolean onDown(MotionEvent e)
{
mLastOnDownEvent = e;
return super.onDown(e);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
if(e1 == …Run Code Online (Sandbox Code Playgroud) 我Wrap和一些Container孩子有一个布局。每个容器都有一个孩子,Text
所述Container具有固定的高度,但柔性的宽度。
如何垂直对齐Text内部Container?我尝试使用alignment: Alignment.centerLeft,但随后容器的宽度跨越了整个父级。
我无法设置 的宽度,Container因为我不知道文本的宽度。
Wrap(
spacing: 3.0, // gap between adjacent chips
runSpacing: 3.0, // gap between lines
children: <Widget>[
new Container(
height: 30,
alignment: Alignment.centerLeft,
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(15),
),
child: Text(
'hallo',
style: TextStyle(background: _paint,),
),
),
...
Run Code Online (Sandbox Code Playgroud)
它应该是这样的 - 但红色文本应该垂直居中:
这段代码有什么问题?
我尝试将长时间点击监听器添加到列表视图,但由于某些原因无法正确:
package ch.futurecom.adaptertest;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class AdapterTestActivity extends ListActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ListView lv = getListView();
lv.setLongClickable(true);
lv.setOnLongClickListener(new OnLongClickListener()
{
@Override
public boolean onLongClick(View v)
{
Toast.makeText(AdapterTestActivity.this, "long clicked", Toast.LENGTH_SHORT).show();
return true;
}
});
lv.setAdapter(new ArrayAdapter<String>(this,R.layout.row,getResources().getStringArray(R.array.items)));
}
}
Run Code Online (Sandbox Code Playgroud)
pastebin links:
AdapterTestActivity.java - > http://pastebin.com/Pw30EkEz
row.xml - > http://pastebin.com/6FajncHT
谢谢!