列表元素的边框和九个补丁背景之间的间隙(LinearLayout)
Gap between the border and the nine patch background of a list element (LinearLayout)
我使用具有不同 "styled" 组件的 ListView。图片中的第一个和第二个组件使用以编程方式绘制的背景。
第三个和第四个元素有九个补丁背景。
当我单击一个元素时,ListView 中的选择器会着色并覆盖所选元素。
我的问题是边框和九色补丁背景之间有间隙。给它任何解决方案来消除这个差距?
Screenshot with selected second list element (programmatically background)
Screenshot with selected fourth list element (nine-patch background)
我找到了解决办法。我从 ListView (setSelector(new StateListDrawable())) 中删除所有选择器状态,并将 OnTouchListener 添加到 ListView。
OnTouchListener 触发不同的方法来设置或删除视图元素绘制背景上的 ColorFilter。 ColorFilter 仅放置在绘制的(九个补丁或编程背景)区域上,而不是间隙上。
public class ClickAndReleaseListener implements View.OnTouchListener
{
/**
* Activity with integrated Adapter (from ListView) to do the triggered methods
*/
public IClickAndReleaseListener releaseListener;
/**
* Call from Activity (with the ListView) ex. listView.setOnTouchListener(new ClickAndReleaseListener(Activity.this))
* @param releaseListener => Activity with implemented Interface
*/
public ClickAndReleaseListener(IClickAndReleaseListener releaseListener)
{
this.releaseListener = releaseListener;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
//Aenderung der Visualisierung für das angeklickte Element.
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
//method find the triggered element and set a ColorFilter at the drawable background
//ex. visibleElement.getBackground().setColorFilter(ColorSpace.getHighlightColorFilter)
releaseListener.setColorFilter(event);
break;
case MotionEvent.ACTION_UP:
//method iterate to all elements and set a null ColorFilter at the drawable background
releaseListener.releaseColorFilter();
break;
}
return false;
}
}
我使用具有不同 "styled" 组件的 ListView。图片中的第一个和第二个组件使用以编程方式绘制的背景。 第三个和第四个元素有九个补丁背景。 当我单击一个元素时,ListView 中的选择器会着色并覆盖所选元素。
我的问题是边框和九色补丁背景之间有间隙。给它任何解决方案来消除这个差距?
Screenshot with selected second list element (programmatically background)
Screenshot with selected fourth list element (nine-patch background)
我找到了解决办法。我从 ListView (setSelector(new StateListDrawable())) 中删除所有选择器状态,并将 OnTouchListener 添加到 ListView。
OnTouchListener 触发不同的方法来设置或删除视图元素绘制背景上的 ColorFilter。 ColorFilter 仅放置在绘制的(九个补丁或编程背景)区域上,而不是间隙上。
public class ClickAndReleaseListener implements View.OnTouchListener
{
/**
* Activity with integrated Adapter (from ListView) to do the triggered methods
*/
public IClickAndReleaseListener releaseListener;
/**
* Call from Activity (with the ListView) ex. listView.setOnTouchListener(new ClickAndReleaseListener(Activity.this))
* @param releaseListener => Activity with implemented Interface
*/
public ClickAndReleaseListener(IClickAndReleaseListener releaseListener)
{
this.releaseListener = releaseListener;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
//Aenderung der Visualisierung für das angeklickte Element.
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
//method find the triggered element and set a ColorFilter at the drawable background
//ex. visibleElement.getBackground().setColorFilter(ColorSpace.getHighlightColorFilter)
releaseListener.setColorFilter(event);
break;
case MotionEvent.ACTION_UP:
//method iterate to all elements and set a null ColorFilter at the drawable background
releaseListener.releaseColorFilter();
break;
}
return false;
}
}