gpt4 book ai didi

java - 在水平 ScrollView 中更改并按住背景颜色 ImageView

转载 作者:太空狗 更新时间:2023-10-29 12:39:14 26 4
gpt4 key购买 nike

在我的应用程序中,我在 Horizo​​ntalScrollView 中使用了 ImageViewImageView图片是从URI(json解析)获取的,图片通过通用图片加载器加载到ImageView
我的问题是如何在项目点击时更改相应图像的 ImageView 背景。
提前致谢

我必须尝试的:

 String RecentBooks="http://";

ArrayList<List<String>> arrrecentbooks= new ArrayList<List<String>> ();

//Horizo​​ntalScrollview 以编程方式创建

HorizontalScrollView scollviewh = new HorizontalScrollView(this);

View v1=null;

LinearLayout linear_pmain = new LinearLayout(this);

linear_pmain.setOrientation(LinearLayout.HORIZONTAL);
// linear_pmain.setBackgroundDrawable(getResources().getDrawable(R.drawable.topshelf));bottomthumbnail

//arrrecentbook 包含从 uri 解析的图像

        int length=arrrecentbooks.size();

for(int j=0;j<length;j++)
{
LayoutInflater vii = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

v1=vii.inflate(R.layout.thumbnailrowlayout, null);

List<String> listitem=arrrecentbooks.get(j);

String rimageurl=listitem.get(13);

String rbookprice=listitem.get(10);

img=(ImageView) v1.findViewById(R.id.imgg);
TextView txt=(TextView) v1.findViewById(R.id.txtg);
txt.setText("Rs."+rbookprice+"/-");
txt.setTypeface(tf,Typeface.NORMAL);


img.setTag(new String[]{listitem.get(0),listitem.get(1),listitem.get(2),listitem.get(3),listitem.get(4),listitem.get(5),listitem.get(6),listitem.get(7),listitem.get(8),listitem.get(9),listitem.get(10),listitem.get(11),listitem.get(12),listitem.get(13),listitem.get(14),listitem.get(15),listitem.get(16),listitem.get(17),listitem.get(18),listitem.get(19),listitem.get(20),"recentbooks"});

//图像加载到 ImageView

            {

imageLoader=new ImageLoader(this);

imageLoader.DisplayImage(rimageurl, this, img);
}
img.setOnClickListener(myIItemClickListener);

linear_pmain.addView(v1);
}

scollviewh.addView(linear_pmain);

lrecentbooks.addView(scollviewh);

//imgeview on itemclick监听器

   public OnClickListener myIItemClickListener = new OnClickListener() {

@Override

public void onClick(View v) {


try{

RelativeLayout borderlyt=(RelativeLayout)findViewById(R.id.Booklyut);

borderlyt.setBackgroundResource(R.drawable.bgorange);

String[] Qtag = (String[]) v.getTag();


Log.d("myItemClickListener", Qtag + "");

//v.setBackgroundResource(R.drawable.bgorange);

Intent itemintent = new Intent(cxt,NoolDashboardDetailPage.class);


Bundle b = new Bundle();

b.putStringArray("iarray", Qtag);

b.putInt("mflag", 0);

itemintent.putExtra("android.intent.extra.INTENT", b);

startActivityForResult(itemintent,2);

}
catch (Exception e) {

// TODO: handle exception
}
}
};

最佳答案

我相信你想在触摸时突出显示图像?

img.setOnClickListener(myIItemClickListener); 下方尝试以下操作:

img.setOnTouchListener(new View.OnTouchListener() {                 
public boolean onTouch(View v, MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
((ImageView) v).setColorFilter(0x44E79B0E, PorterDuff.Mode.SRC_ATOP);
}
if ((e.getAction() == MotionEvent.ACTION_UP) || (e.getAction() == MotionEvent.ACTION_CANCEL)) {
((ImageView) v).setColorFilter(null);
}
return false;
}
});

将“0x44E79B0E”更改为您想要的透明颜色。

如果它适合你,请告诉我。

关于java - 在水平 ScrollView 中更改并按住背景颜色 ImageView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31739615/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com