listview - 以编程方式为listview项设置负边距

时间:2016-01-02 18:59:44

标签: android listview android-listview imageview margin

我有查看属于listview的项目的负余量的问题。

我的项目如下:

enter image description here

我想提升第二项和第三项,依此类推。最终效果应如下所示

enter image description here

我尝试使用setTop方法。

 private class MyCustomAdapter extends ArrayAdapter<Integer> {

        public MyCustomAdapter()
        {
            super(ListOfBeaconPlaces.this, R.layout.list_of_places_item_view, drawables);
        }

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

            if (takenView == null)
            {
                takenView = getLayoutInflater().inflate(R.layout.list_of_places_item_view, null, false);
            }
            final CuttedImageView cuttedImage = (CuttedImageView) takenView.findViewById(R.id.list_item_view);
            cuttedImage.setImageResource(drawables.get(position));
            if (cuttedImage.getHeightOfDrawnTransparentTriangle() != 0)
            {
                cuttedImage.setTop( (int)-cuttedImage.getHeightOfDrawnTransparentTriangle());
            }

            return takenView;
        }
    }

CuttedImageView是我的自定义类,继承自ImageView

在我第一次在布局上绘制它之后,我知道这个三角形的高度,但这不是问题。我尝试使用LayoutParameters,但它对我的工作也不起作用。

是否有可能使整个项目保证金为负?

我看到了一个问题,谈论在线性布局或相对布局中或在列表视图项目内设置项目的边距,但我无法找到整个项目的边际变化。

1 个答案:

答案 0 :(得分:1)

在xml文件中,在listview中将分隔符高度设置为负数以获得重叠效果。

像这样

<LinearLayout android:orientation="vertical" ...>
    <RelativeLayout ... /> <!-- Top action bar -->
    <TextView ... />
    <TextView ... />
    <LinearLayout android:orientation="horizontal" ... /> <!-- table header -->
    <ListView
        android:layout_height="0dp"
        android:layout_weight="1"
        ... />
    <AdView ... />
    <RelativeLayout ... /> <!-- bottom action bar -->
    <Button ... /> <!-- The one that is currently cut off -->
</LinearLayout>