简体   繁体   English

如何在两个列表片段之间添加一个?

[英]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.

相关问题 Android片段-如果我在彼此之上添加两个片段,那么删除顶部片段时的回调是什么? - android fragments - if i add two fragments on top of each other what is callback when top one is removed? 如何从我的片段之一添加数据,并将其传递给我的适配器,并将其设置为我的数组列表? - How can I add data from one of my fragments, and pass it to my adapter, and set it to my array list? 如何以编程方式将多个列表片段添加到单个活动中? - How can I programmatically add multiple list fragments to a single activity? 如何在一个活动中添加两个片段 - how to add two fragments in one activity 我可以在一个 NavHostFragment 中启动两个片段吗? - Can I start two fragments in one NavHostFragment? 一个屏幕上有两个片段(活动),一个片段如何使用EventBus更新另一个片段 - With two fragments on one screen (activity), how can one fragment update the other with EventBus 如何将 WebView 添加到片段之一 - How do I add WebView to one of the fragments 如何在不使用xml的情况下在表行中添加两个垂直方向(一个在另一个下方)的textview? - How to add two textview with orientation vertical(One below other) in a table row without using xml? 如何在一个主菜单下调用多个xml文件,而又不能同时使用Fragments? - how can I have several xml files to be invoked below one main menu and I don't utilize Fragments at the same time? 垂直显示两个文本字段(在列表视图中一个显示在另一个下方) - Display two text field in vertically(one below the other in list view)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM