[英]How can I add two list fragments one below the other?
I want to add two listfragments (listfragment1 and listfragment2) whose list are populated dynamically from webservice call. 我想添加两个listfragments(listfragment1和listfragment2),它们的列表是通过webservice调用动态填充的。 The listfragment2 is suppose to be just below the listfragment1 such that if more content is fetched in listfragment1 then listfragment2 should move/slide down.
假设listfragment2恰好位于listfragment1的下方,因此,如果在listfragment1中获取了更多内容,则listfragment2应该向下移动/滑动。
Why not wrap two listfragments inside a linearlayout. 为什么不在线性布局中包装两个列表片段。 you should use two different adapters for each listfragment.
您应该为每个列表片段使用两个不同的适配器。 This is more like supporting two fragments in one activity for larger screen.
这更像是在一个活动中支持两个片段以获得更大的屏幕。 One with the page titles and the other with page details.
一个带有页面标题,另一个带有页面细节。
Check this sample to start with.Link - supporting tablets. 检查此示例以开始。Link- 支持平板电脑。
Main Layout: 主要布局:
<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>
add fragments in activity: 在活动中添加片段:
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();}
make custom listview with blocking verticle scrolling.. 进行自定义listview并阻止垂直滚动。
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) {
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.