我是Android的新手。我使用SimpleAdapter
生成了Listview。 ListView连续显示3个文本视图。我想再添加一个textview并保持隐藏,直到用户滑动Listview行,即当用户滑动所有4个textview时应该是可见的。任何人都可以建议我如何做到这一点。任何链接或教程都会有所帮助。
答案 0 :(得分:1)
从开发者文档中查看design pattern和how to implement it。
答案 1 :(得分:0)
所以你想要的是一个固定高度的ListView。应用layout_weight
属性来控制ListView和其他对象的高度。我猜ListView下面还有其他对象,否则你不希望它有一个固定的高度。
答案 2 :(得分:0)
1st:你必须创建自己的自定义列表视图。
第二名:使用此
navigaList.setOnTouchListener(swipeDetector);
navigaList.setOnItemClickListener(listener);
OnItemClickListener listener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
if(swipeDetector.swipeDetected()) {
if(swipeDetector.getAction() == Action.RL) {
} else {
}
}
};
然后你必须使用这个类
来检测滑动public class SwipeDetector implements View.OnTouchListener {
public static enum Action {
LR, // Left to Right
RL, // Right to Left
TB, // Top to bottom
BT, // Bottom to Top
None // when no action was detected
}
private static final String logTag = "SwipeDetector";
private static final int MIN_DISTANCE = 100;
private float downX, downY, upX, upY;
private Action mSwipeDetected = Action.None;
public boolean swipeDetected() {
return mSwipeDetected != Action.None;
}
public Action getAction() {
return mSwipeDetected;
}
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
downX = event.getX();
downY = event.getY();
mSwipeDetected = Action.None;
return false; // allow other events like Click to be processed
}
case MotionEvent.ACTION_MOVE: {
upX = event.getX();
upY = event.getY();
float deltaX = downX - upX;
float deltaY = downY - upY;
// horizontal swipe detection
if (Math.abs(deltaX) > MIN_DISTANCE) {
// left or right
if (deltaX < 0) {
Logger.show(Log.INFO,logTag, "Swipe Left to Right");
mSwipeDetected = Action.LR;
return true;
}
if (deltaX > 0) {
Logger.show(Log.INFO,logTag, "Swipe Right to Left");
mSwipeDetected = Action.RL;
return true;
}
} else
// vertical swipe detection
if (Math.abs(deltaY) > MIN_DISTANCE) {
// top or down
if (deltaY < 0) {
Logger.show(Log.INFO,logTag, "Swipe Top to Bottom");
mSwipeDetected = Action.TB;
return false;
}
if (deltaY > 0) {
Logger.show(Log.INFO,logTag, "Swipe Bottom to Top");
mSwipeDetected = Action.BT;
return false;
}
}
return true;
}
}
return false;
}
}
希望这会对你有所帮助:)。
你可能会读到这个: here