- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用这个 CoverFlow:http://www.inter-fuser.com/2010/02/android-coverflow-widget-v2.html .
我用这个 coverflow 创建了一个个人应用程序,但我有一个问题:我想在选择项目(框)时更改背景(如此链接:http://www.macgeneration.com/news/voir/187282/squire-un-media-center-elegant-en-preparation)。我已经尝试了一切但没有成功......可能我需要做一个其他的适配器 View ,我不知道。如果你能帮助我,那将是完美的一天!
对不起我的英语!
这是我的java代码:
`public class CoverFlowExample extends Activity {
/** Called when the activity is first created. */`
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Use this if you want to use XML layout file
setContentView(R.layout.main);
CoverFlow coverFlow;
coverFlow = (CoverFlow) findViewById(R.id.coverflow);
` coverFlow.setAdapter(new ImageAdapter(this));`
` ImageAdapter coverImageAdapter = new ImageAdapter(this);`
` coverImageAdapter.createReflectedImages();`
` coverFlow.setAdapter(coverImageAdapter);`
` coverFlow.setSpacing(-145);`
` coverFlow.setSelection(0, true);`
` coverFlow.setAnimationDuration(1000);`
}
` public class ImageAdapter extends BaseAdapter {`
` int mGalleryItemBackground;`
` private Context mContext;`
` private FileInputStream fis;`
` private Integer[] mImageIds = {
R.drawable.demolitionman,
R.drawable.diehard1,
R.drawable.diehard2,
R.drawable.diehard3,
R.drawable.diehard4,
R.drawable.district9,
R.drawable.essai,
R.drawable.essai2,
R.drawable.dracula
};`
private ImageView[] mImages;
public ImageAdapter(Context c) {
mContext = c;
mImages = new ImageView[mImageIds.length];
}
` public boolean createReflectedImages() {
//The gap we want between the reflection and the original image
final int reflectionGap = 0;`
int index = 0;
for (int imageId : mImageIds) {
Bitmap originalImage = BitmapFactory.decodeResource(getResources(),
imageId);
int width = originalImage.getWidth();
int height = originalImage.getHeight();
//This will not scale but will flip on the Y axis
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
//Create a Bitmap with the flip matrix applied to it.
//We only want the bottom half of the image
Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height/2, width, height/2, matrix, false);
//Create a new bitmap with same width but taller to fit reflection
Bitmap bitmapWithReflection = Bitmap.createBitmap(width
, (height + height/2), Config.ARGB_8888);
//Create a new Canvas with the bitmap that's big enough for
//the image plus gap plus reflection
Canvas canvas = new Canvas(bitmapWithReflection);
//Draw in the original image
canvas.drawBitmap(originalImage, 0, 0, null);
//Draw in the gap
Paint deafaultPaint = new Paint();
canvas.drawRect(0, height, width, height + reflectionGap, deafaultPaint);
//Draw in the reflection
canvas.drawBitmap(reflectionImage,0, height + reflectionGap, null);
//Create a shader that is a linear gradient that covers the reflection
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0,
bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff,
TileMode.CLAMP);
//Set the paint to use this shader (linear gradient)
paint.setShader(shader);
//Set the Transfer mode to be porter duff and destination in
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
//Draw a rectangle using the paint with our linear gradient
canvas.drawRect(0, height, width,
bitmapWithReflection.getHeight() + reflectionGap, paint);
ImageView imageView = new ImageView(mContext);
imageView.setImageBitmap(bitmapWithReflection);
imageView.setLayoutParams(new CoverFlow.LayoutParams(180, 180));
//imageView.setScaleType(ScaleType.MATRIX);
imageView.setScaleType(ScaleType.FIT_CENTER);
mImages[index++] = imageView;
}
return true;
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
//Use this code if you want to load from resources
ImageView i = new ImageView(mContext);
//i.setImageResource(mImageIds[position]);
i.setImageDrawable( mImages[position].getDrawable() );
i.setLayoutParams(new CoverFlow.LayoutParams(340, 340));
i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
//Make sure we set anti-aliasing otherwise we get jaggies
BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
drawable.setAntiAlias(true);
return i;
//return mImages[position];
}
` /** Returns the size (0.0f to 1.0f) of the views
* depending on the 'offset' to the center. */
public float getScale(boolean focused, int offset) {
/* Formula: 1 / (2 ^ offset) */
return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset)));`
` }`
}
`
最佳答案
这对你来说很好。
您可以在 getview 方法中实现此目的。您将使用 setOnItemSelectedListener 获得选择位置。
如下所示是您必须在 Coverflow 中设置的监听器。
coverFlow.setOnItemSelectedListener(new SelectListener(this));
int sel_pos;
public class ImageAdapter extends BaseAdapter
{
private Context mContext;
private Integer[] UnselectedImage = {
R.drawable.a,
R.drawable.b,
R.drawable.c,
R.drawable.d,
R.drawable.e,
R.drawable.f
};
private Integer[] selectedImage =
{
R.drawable.a_sel,
R.drawable.b_sel,
R.drawable.c_sel,
R.drawable.d_sel,
R.drawable.e_sel,
R.drawable.f_sel,
};
public ImageAdapter(Context c)
{
mContext = c;
}
public int getCount() {
return selectedImage.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressWarnings("deprecation")
public View getView(int position, View convertView, ViewGroup parent)
{
final ImageView i = new ImageView(mContext);
i.refreshDrawableState();
i.setDrawingCacheEnabled(false);
i.setAdjustViewBounds(true);
Log.e("position==", ""+position);
if(sel_pos==position)
{
i.setImageResource(selectedImage[position]);
}
else
{
i.setImageResource(UnselectedImage[position]);
}
i.setLayoutParams(new CoverFlow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
drawable.setAntiAlias(true);
return i;
}
private class SelectListener implements AdapterView.OnItemSelectedListener
{
public SelectListener(Context c)
{
}
@SuppressWarnings("deprecation")
public void onItemSelected(AdapterView<?> parent, View v, int position,long id)
{
Log.e("Changed----->", "" + position);
// Zoom the new selected view
try
{
sel_pos = position;
coverImageAdapter.notifyDataSetChanged();
} catch (Exception animate)
{
}
}
public void onNothingSelected(AdapterView<?> parent) {
}
}
享受代码。
关于android - 更改所选项目的背景 Coverflow android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15028088/
SO亲爱的 friend 们: 2014 年 3 月 18 日。我正在处理一种情况,在使用 ng-repeat 时,数组内的元素(我从 Json 字符串中获取)更改了原始顺序。 需要明确的是,数组中的
有很多问题询问如何在 JavaScript 单击处理程序中更改 div 的类,例如,此处:Change Div style onclick .我理解得很好(只需更改 .className),并且它有效
我从access导入了一个数据库到mysql,但其中一个表的列名“股数”带有空格,但我尝试更改、替换甚至删除列名,但失败了。任何人都可以帮助解决这一问题 String UpdateQuary = "U
我正在做一个随机的学校元素。 目前,我有一个包含两个 CSS 的页面。一种用于正常 View ,一种用于残障人士 View 。 此页面还包括两个按钮,它们将更改使用的样式表。 function c
我需要使用 javascript 更改 HTML 元素中的文本,但我不知道该怎么做。 ¿有什么帮助吗? 我把它定义成这样: Text I want to change. 我正在尝试这样做: docum
我在它自己的文件 nav_bar.shtml 中有一个主导航栏,每个其他页面都包含该导航栏。这个菜单栏是一个 jQuery 菜单栏(ApyCom 是销售这些导航栏的公司的名称)。导航栏上的元素如何确定
我正在摆弄我的代码,并开始想知道这个变化是否来自: if(array[index] == 0) 对此: if(!array[index] != 0) 可能会影响任何代码,或者它只是做同样的事情而我不需
我一直在想办法调整控制台窗口的大小。这是我正在使用的函数的代码: #include #include #define WIDTH 70 #define HEIGHT 35 HANDLE wHnd;
我有很多情况会导致相同的消息框警报。 有没有比做几个 if 语句更简单/更好的解决方案? PRODUCTS BOX1 BOX2 BOX3
我有一个包含这些元素的 XELEMENT B Bob Petier 19310227 1 我想像这样转换前缀。 B Bob Pet
我使用 MySQL 5.6 遇到了这种情况: 此查询有效并返回预期结果: select * from some_table where a = 'b' and metadata->>"$.countr
我想知道是否有人知道可以检测 R 中日期列格式的任何中断的包或函数,即检测日期向量格式更改的位置,例如: 11/2/90 12/2/90 . . . 15/Feb/1990 16/Feb/1990 .
我希望能够在小部件显示后更改 GtkButton 的标签 char *ButtonStance == "Connect"; GtkWidget *EntryButton = gtk_button_ne
我正在使用 Altera DE2 FPGA 开发板并尝试使用 SD 卡端口和音频线路输出。我正在使用 VHDL 和 C 进行编程,但由于缺乏经验/知识,我在 C 部分遇到了困难。 目前,我可以从 SD
注意到这个链接后: http://www.newscientist.com/blogs/nstv/2010/12/best-videos-of-2010-progress-bar-illusion.h
我想知道在某些情况下,即使剧本任务已成功执行并且 ok=2,ansible 也会显示“changed=0”。使用 Rest API 和 uri 模块时会发生这种情况。我试图找到解释但没有成功。谁能告诉
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: add buttons to push notification alert 是否可以在远程通知显示的警报框中指定有
当您的 TabBarController 中有超过 5 个 View Controller 时,系统会自动为您设置一个“更多” View 。是否可以更改此 View 中导航栏的颜色以匹配我正在使用的颜
如何更改.AndroidStudioBeta文件夹的位置,默认情况下,该文件夹位于Windows中的\ .. \ User \ .AndroidStudioBeta,而不会破坏任何内容? /编辑: 找
我目前正在尝试将更具功能性的编程风格应用于涉及低级(基于 LWJGL)GUI 开发的项目。显然,在这种情况下,需要携带很多状态,这在当前版本中是可变的。我的目标是最终拥有一个完全不可变的状态,以避免状
我是一名优秀的程序员,十分优秀!