我有一个GridView来显示一些对象,并且在视觉上每个对象都有一个图像图标和一个文本标签.我还希望图像图标在单击时具有一些"推动和弹出"效果,也就是说,按下时,图像将向右下方移动一小段距离,并在释放后返回其原始位置.
对象(及其图像图标)来自某些动态源.我的直觉是为每个项创建一个StateListDrawable,它有两种状态:是否按下.对于GridView项目视图,我会使用一个Button,它可以容纳Drawable和一个标签,完全满足我的要求.
我定义了一个item类来包装原始对象:
public class GridItem<T> {
public static final int ICON_OFFSET = 4;
private StateListDrawable mIcon;
private String mLabel;
private T mObject;
public Drawable getIcon() {
return mIcon;
}
public void setIcon(Drawable d) {
if (null == d) {
mIcon = null;
}else if(d instanceof StateListDrawable) {
mIcon = (StateListDrawable) d;
} else {
InsetDrawable d1 = new InsetDrawable(d, 0, 0, ICON_OFFSET, ICON_OFFSET);
InsetDrawable d2 = new InsetDrawable(d, ICON_OFFSET, ICON_OFFSET, 0, 0);
mIcon = new StateListDrawable();
mIcon.addState(new int[] { …
Run Code Online (Sandbox Code Playgroud) 这是我的自定义选择器(StateListDrawable)
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/common_cell_background" />
<item
android:state_pressed="true"
android:drawable="@drawable/common_cell_background_highlight" />
<item
android:state_focused="true"
android:drawable="@drawable/common_cell_background_highlight" />
<item
android:state_selected="true"
android:drawable="@drawable/common_cell_background_highlight" />
</selector>
Run Code Online (Sandbox Code Playgroud)
common_cell_background和common_cell_background_highlight都是XML.代码如下:
common_cell_background.xml
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/common_cell_background_bitmap"
android:tileMode="repeat"
android:dither="true">
</bitmap>
Run Code Online (Sandbox Code Playgroud)
common_cell_background_highlight.xml
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/common_cell_background_bitmap_highlight"
android:tileMode="repeat"
android:dither="true">
</bitmap>
Run Code Online (Sandbox Code Playgroud)
位图也完全相同.亮点只是稍微轻一点,没有其他差异.两个位图都是PNG文件.
现在我开始了
convertView.setBackgroundResource(R.drawable.list_item_background);
Run Code Online (Sandbox Code Playgroud)
这是问题所在.我的common_cell_background没有重复,它已经拉长了.但是,当我触摸列表背景的单元格时,令人惊讶的是变为common_cell_background_highlight并猜测是什么?一切都很好,它应该像它应该重复.我不知道问题出在哪里,为什么我的背景不会重复突出显示.有什么想法吗?
我想要以下内容: .) 在单击时更改其背景的文本视图 .) 保持该背景直到再次单击
这一切都归结为“可检查”状态,但我无法弄清楚这究竟是如何工作的。这是我用于背景的xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- pressed -->
<item android:drawable="@drawable/menuselected"
android:state_pressed="true" />
<!-- checked -->
<item android:drawable="@drawable/menuselected"
android:state_checked="true" />
<!-- default -->
<item android:drawable="@drawable/transpixel"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
更新:它现在部分工作。我为我的自定义 Textview采用了http://kmansoft.com/2011/01/11/checkable-image-button/ 中的大部分代码。我实际上是这样做的,我也需要单选按钮的功能。现在我可以检查 Textview,但我无法取消选中它。有人明白为什么会这样吗?
可能重复:
国家,州,省WebService?
此"orignal"链接仅显示Web服务或我可以获取手动插入列表的位置.有没有人知道一个库/内置的类/ dll,不需要为数据命中另一台服务器而不需要手动输入每个状态?
我目前正在为加拿大,墨西哥和巴西(可能更快)添加对ASP.NET网站的支持.用户可以通过下拉列表输入他们的物理地址,包括他们的状态.我目前手动添加美国各州:
states.Add(new ListItem("Alabama", "AL"));
states.Add(new ListItem("Alaska", "AK"));
etc ...
Run Code Online (Sandbox Code Playgroud)
在我开始为其他国家/地区手动创建列表之前,是否有一些预先构建的类或库可以通过传递国家代码给我一个州列表?示例:someClass.getStatesFor("BR");
//将返回巴西的列表/状态集合.