很抱歉没有发布任何代码。搜索堆栈溢出和谷歌,但没有找到适当的解决方案,因此,请您帮助我,如果您有任何想法或诀窍。
请求:
我有很多按钮,根据网页的requirement.and创建程序,用灰度设置所有按钮的背景图像。我已经完成了这个部分,但是当滚动水平拼图时,我想改变那个按钮(在滚动的时候是可见的),背景图像颜色(初始加载灰度),让我们假设10秒按钮,背景设置为初始状态(灰度)。
主题:
更改按钮背景图像时,斥责上可见视图的按钮。时间间隔(10秒)。
`
问题:
我无法获得按钮当前可见的水平视图和更改按钮的背景彩色图像(第一次查看加载)。我只想以编程的方式实现这一点,因为所有的图像都是从服务器端获取的。
任何想法,如何做这项工作或任何参考为这一任务。
注意:我创建button视图并设置图像背景,在linearlayout上添加图像,添加线性布局(其他mainlinearlayout ),并在horizontalview布局上添加主线性布局。
我的代码示例
public class CustomAdWithTitle extends LinearLayout{
private LinearLayout LinearCollectionAds;
private List<CommericalClassifiedAds> listCommericalAds;
HorizontalScrollView commercialH = new HorizontalScrollView(mcontext);
commercialH.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
LinearLayout commercialL = new LinearLayout(mcontext);
commercialL.setOrientation(LinearLayout.HORIZONTAL);
commercialL.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
LinearLayout LinearCollectionAds= new LinearLayout(mcontext);
LinearCollectionAds.setOrientation(LinearLayout.VERTICAL);
LinearCollectionAds.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
for (int i = 0; i < listCommericalAds.size(); i++) {
try {
commercialL.addView(listCommericalAds.get(i));
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
commercialH.addView(commercialL);
LinearCollectionAds.addView(commercialH);
this.addView(LinearCollectionAds);
}.
列表的CommericalClassifiedAds,它可以返回相对的按钮视图。我只是添加按钮背景和设置灰度缩放这里第一次加载视图。
public class CommericalClassifiedAds extends RelativeLayout {
}发布于 2015-01-30 11:26:51
让我看看我是不是把你弄对了。要更改按钮后面的图像,可以使用StateListDrawable
StateListDrawable stateList = new StateListDrawable();
stateList.addState(new int[] { android.R.attr.state_selected }, bitmapFromServer);
stateList.addState(new int[] {}, bitmapGrayScale);创建每个CommericalClassifiedAds背景而不是按钮背景时,将其添加到每个背景中。Register a Scroll listener到commercialH并在其中更新UI。
private static boolean wait;
private static Handler handler = new Handler();
private static Runnable delayRunnable = new Runnable() {
@Override
public void run() {
int childcount = commercialL.getChildCount();
for (int i=0; i < childcount; i++){
commercialL.getChildAt(i).setSelected(false);
}
};
@Override
public void onScrollChanged() {
//this method can be called very frequently so only run selective
if (!wait) {
handler.removeCallbacks(delayRunnable);
wait = true;
int childcount = commercialL.getChildCount();
for (int i=0; i < childcount; i++){
commercialL.getChildAt(i).setSelected(true);
}
handler.postDelayed(new Runnable() {
@Override
public void run() {
wait = false;
}
}, 2000);
handler.postDelayed(delayRunnable, 10000);
}
}如果运行缓慢,我将首先重新考虑布局结构。看起来您的布局比需要的要多一些,然后优化onScroll。
我留下一个错误的预约,它没有测试,但它可以给你如何解决问题的想法。
https://stackoverflow.com/questions/28140902
复制相似问题