我想添加两个listfragments(listfragment1和listfragment2),其列表是从webservice调用动态填充的。 listfragment2假设位于listfragment1的正下方,这样如果在listfragment1中获取了更多内容,那么listfragment2应该移动/向下滑动。
答案 0 :(得分:0)
为什么不在linearlayout中包装两个listfragments。你应该为每个listfragment使用两个不同的适配器。这更像是在一个活动中支持两个片段以获得更大的屏幕。一个是页面标题,另一个是页面详细信息。
检查此示例以开始。链接 - supporting tablets.
答案 1 :(得分:0)
主要布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/lstFragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
<LinearLayout
android:id="@+id/lstFragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
</LinearLayout>
在活动中添加片段:
addFragment(R.id.lstFragment1, new lstFragment1());
addFragment(R.id.lstFragment2, new lstFragment2());
public void addFragment(int layoutId, Fragment fragment) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(layoutId, fragment);
ft.commit();}
使用阻止垂直滚动来制作自定义列表视图..
public class IjoomerListView extends ListView {
@SuppressWarnings("unused")
private static final int SWIPE_MIN_DISTANCE = 50;
@SuppressWarnings("unused")
private static final int SWIPE_THRESHOLD_VELOCITY = 100;
@SuppressWarnings("unused")
private GestureDetector gDetector;
@SuppressWarnings("unused")
private boolean isFling;
private float mDiffX;
private float mDiffY;
private float mLastX;
private float mLastY;
/**
* Overrides method
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// reset difference values
mDiffX = 0;
mDiffY = 0;
mLastX = ev.getX();
mLastY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
mDiffX += Math.abs(curX - mLastX);
mDiffY += Math.abs(curY - mLastY);
mLastX = curX;
mLastY = curY;
// don't intercept event, when user tries to scroll vertically
if (mDiffX < mDiffY) {
return false; // do not react to horizontal touch events, these
// events will be passed to your list item view
}
}
return super.onInterceptTouchEvent(ev);
}
public IjoomerListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
public IjoomerListView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public IjoomerListView(Context context) {
super(context);
init(context);
}
private void init(Context mContext) {
}
}