ListView包含重叠元素

时间:2014-01-16 13:35:22

标签: android listview scrollview

实施此类布局的最佳解决方案是:enter image description here

我试过:

  1. listview with negative divider(行需要时的错误解决方案) 不同的高度)
  2. 使用relativelayout滚动视图(错误的解决方案 因为内存消耗)
  3. 滚动两个列表视图 同时(非常糟糕)

1 个答案:

答案 0 :(得分:-1)

为列表视图项创建自定义布局。

 <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="2" >

        <LinearLayout
            android:id="@+id/evenSideLayout"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_marginTop="25dp"
            android:layout_weight="1"
            android:orientation="vertical" >
        </LinearLayout>

        <LinearLayout
            android:id="@+id/oddSideLayout"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_marginTop="0dp"
            android:layout_weight="1"
            android:orientation="vertical" >
        </LinearLayout>
    </LinearLayout>

现在在您的自定义适配器中...管理布局可见性。像

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

        convertView = inflater.inflate(R.layout.item_option_layout, parent,
                false);
        LinearLayout oddLayout = (LinearLayout) convertView.findViewById(R.id.oddLayout);
        LinearLayout evenLayout = (LinearLayout) convertView.findViewById(R.id.evenLayout);
        if(position%2==0)
        {
            evenLayout.setVisibility(View.VISIBLE);
            oddLayout.setVisibility(View.GONE);
        }
        else
        {
            evenLayout.setVisibility(View.GONE);
            oddLayout.setVisibility(View.VISIBLE);
        }

        return convertView;
    }