- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个 Logo 测验,这很有效,但我无法弄清楚如何从 ImageAdapter 修改特定图像。任何指导将不胜感激。谢谢!
这是我的测验 Activity :
public class QuizActivity extends Activity {
private InterstitialAd interstitial;
private static int SIZE = 50;
public static int location;
private int counter = 0;
// initialize buttons
public static ImageButton buttons[] = new ImageButton[SIZE];
// array names
public static String[] names = { "hannibal", "orphan black", "lord of the rings",
"pretty little liars", "harry potter", "star trek",
"the fault in our stars", "iron man", "thor", "frozen",
"harry potter", "game of thrones", "hannibal", "doctor who",
"sherlock", "attack on titan", "teen wolf", "game of thrones",
"doctor who", "sherlock", "supernatural", "the hunger games",
"american horror story", "breaking bad", "attack on titan",
"teen wolf", "doctor who", "sherlock", "supernatural", "sherlock",
"arrow", "the big bang theory", "mad men", "arrested development",
"game of thrones", "breaking bad", "sons of anarchy", "the graduate",
"et", "scooby doo", "wizard of oz", "linux", "simpsons", "iron man", "wonder woman",
"green lantern", "flash", "captain america", "thor", "the picture of dorian gray"
};
// array images
public int[] images = { R.drawable.image1, R.drawable.image2,
R.drawable.image3, R.drawable.image4, R.drawable.image5,
R.drawable.image6, R.drawable.image7, R.drawable.image8,
R.drawable.image9, R.drawable.image10, R.drawable.image11,
R.drawable.image12, R.drawable.image13, R.drawable.image14,
R.drawable.image15, R.drawable.image16, R.drawable.image17,
R.drawable.image18, R.drawable.image19, R.drawable.image20,
R.drawable.image21, R.drawable.image22, R.drawable.image23,
R.drawable.image24, R.drawable.image25, R.drawable.image26,
R.drawable.image27, R.drawable.image28, R.drawable.image29,
R.drawable.image30,
R.drawable.image31, R.drawable.image32, R.drawable.image33,
R.drawable.image34, R.drawable.image35, R.drawable.image36,
R.drawable.image37, R.drawable.image38, R.drawable.image39,
R.drawable.image40,
R.drawable.image41, R.drawable.image42, R.drawable.image43,
R.drawable.image44, R.drawable.image45, R.drawable.image46,
R.drawable.image47, R.drawable.image48, R.drawable.image49,
R.drawable.image50};
GridView gridview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Toast.makeText(QuizActivity.this, "" + position, Toast.LENGTH_SHORT).show();
// PopUpActivity
Intent intent = new Intent(QuizActivity.this, PopUpWindow.class);
intent.putExtra("position", position);
intent.putExtra("images", images);
intent.putExtra("names", names);
startActivity(intent);
counter++;
if (counter == 2) {
counter = 0;
// ad
displayInterstitial();
}
}
});
}
// Invoke displayInterstitial() when you are ready to display an
// interstitial.
public void displayInterstitial() {
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest);
if (interstitial.isLoaded()) {
interstitial.show();
}
}
public void dimImage(){
//item..setAlpha(300); <- This is where I am confused
}
}
还有我的 ImageAdapter 类:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
public Integer[] mThumbIds = {
R.drawable.image1, R.drawable.image2,
R.drawable.image3, R.drawable.image4,
R.drawable.image5, R.drawable.image6,
R.drawable.image7, R.drawable.image8,
R.drawable.image9, R.drawable.image10,
R.drawable.image11, R.drawable.image12,
R.drawable.image13, R.drawable.image14,
R.drawable.image15, R.drawable.image16,
R.drawable.image17, R.drawable.image18,
R.drawable.image19, R.drawable.image20,
R.drawable.image21, R.drawable.image22
};
最佳答案
是的,随机是正确的。您可以让适配器跟踪哪些项目已变暗,并检查 getView 中特定项目的设置:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private int mSize;
private boolean [] mDim;
public ImageAdapter(Context c, int size) {
mContext = c;
mSize = size;
mDim = new boolean[size];
}
public void dimImage(int position) {
mDim[position] = true;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
imageView.setAlpha(mDim[position] ? 0.5f : 1.0f);
return imageView;
}
}
在你的activity中,把adapter放在一个字段中,用SIZE构造adapter,当你想调暗图像时,调用adapter.dimImage(position),然后是notifyDataSetChanged:
public class QuizActivity extends Activity {
private ImageAdapter adapter;
private GridView gridview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adapter = new ImageAdapter(this, SIZE);
gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(adapter);
...
}
public void dimImage(){
adapter.dimImage(location); // not sure if location represents the image index
adapter.notifyDataSetChanged();
}
关于android - 如何从 ImageAdapter Grid View 类调暗 ImageView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27242031/
我希望带有 ImageAdapter 的 GridView 具有自定义按下的按钮。我已经有了自定义按钮,但是 onClick 它会在按钮周围创建一个很大的橙色 onClick 东西。我只希望 onCl
我目前正在开发一个应用程序,它允许用户从 GridView 库中选择一个 ImageView 并单独显示它并展示它的所有美感。 GridView 在 fragment 上,然后将数据传递给 Activ
下面是我的代码。我正在尝试将我的 SD 卡中的图像检索到 GridView 中。我的代码有问题。我不知道如何将图像设置到我的 ImageView 中。我的 ImageAdapter 中出现错误“Ima
我有一个 getView() 的 Android Gallery ImageAdapter 实现,如下所示: public View getView(int arg0, View arg1, View
每次我测试我的应用程序时,它都会在闪屏后崩溃,并给出如下错误: 02-14 13:03:29.305: A/libc(9935): Fatal signal 11 (SIGSEGV) at 0x000
我正在尝试按照 ImageView 和 GalleryView 教程在 fragment 类中添加一个 galleryview,但是出现无法将 ImageAdapter 应用于 Tab1Fragmen
ListView 代码如下: public final static String ITEM_TITLE = "title"; public final static String ITE
我用来将图像从 SD 卡显示到 GridView 的 ImageAdapter 代码导致图像重复。同一组图像(例如 10 个)在 GridView 中重复。 这是我的适配器代码: private cl
我正在使用带有 ImageAdapter 的 Gallery 加载它,并使用 ImageViews 从我的资源中提取图像。我的问题是在我的适配器中传递给 getView() 方法的 convertVi
我做了什么 我在布局中创建了一个 GridView。这个 GridView 我想填充我在 Google 文档中创建的 ImageAdapter:Hello GridView 我的图片的图片路径,我保存
我的安卓有问题。我想使用以下代码为图库设置 ImageAdapter: Integer[] images = {R.drawable.image01}; static int counter = 0;
我有这个用于 android 的 listView 的 ImageAdapter: @Override public View getView(int position, View convertVi
我正在尝试使用 ImageAdapter 在 GridView 中显示我的 Activity 图像。都是基本功能,即使我匹配来自多个来源的代码,但我的代码没有运行,这是什么问题?ImageAdapte
好吧,在周末取得了很多进展之后,我陷入了 gridView 和 ImageAdapter 的困境。到目前为止,我所做的就是我的主要 Activity 获取用户选择的标签,执行查询并返回 json_ec
正如标题已经提到的,我想更改我的 ImageView onClick 吗?我在 ImageAdapter 中制作了一个包含 4 个项目的 GridView。当我单击每个 ImageView 时,它会在
我是 Android 新手,在“扩展 Fragment”上实现 GridView 时遇到一个问题。 Tab2SalonActivity.java public class Tab2SalonActiv
我正在实现一个支持多项选择的图片库。主要布局是 GridView,它使用自定义 Adapter。每个显示的项目都是 ImageView + CheckBox 的组合。如果选中了多个复选框,我想通过触摸
我正在使用 ImageAdapter extends BaseAdapter 来扩展 gridview。 Gridview 有两个 textview。我想为其中之一设置自定义字体。在 ImageAda
我正在尝试创建一个 Logo 测验,这很有效,但我无法弄清楚如何从 ImageAdapter 修改特定图像。任何指导将不胜感激。谢谢! 这是我的测验 Activity : public class Q
我正在使用 google 文档中提供的示例 ImageAdpater 来使用可绘制对象填充 gridview。我想要做的是用 xml 文件中的一组可绘制对象填充 gridview。 我使用 Typed
我是一名优秀的程序员,十分优秀!