gpt4 book ai didi

Android viewflipper 和画廊

转载 作者:行者123 更新时间:2023-11-30 03:57:19 27 4
gpt4 key购买 nike

我正在尝试开发一个应用程序,其中包含一个带 View 翻转器的画廊。

图库显示所有图像。我想要做的是, View 翻转器中显示的图像应该在图库中突出显示。

目前我可以在 onClick 上突出显示它。但无法在两者之间进行通信。

我试过用下面的方法

viewflipper.getDisplayedChild();

但它不起作用。

以下是我的代码

public class SliderActivity extends Activity 
{
int mFlipping = 0 ;
public int currentimageindex=0;
Timer timer;
TimerTask task;
ImageView slidingimage;
android.widget.ViewFlipper flipper;
Gallery gallery;


private int[] IMAGE_IDS =
{
R.drawable.android0, R.drawable.android1, R.drawable.android2,R.drawable.android3,R.drawable.android4
};



@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mygame);
flipper = (android.widget.ViewFlipper) findViewById(R.id.flipper1);

for(int i=0;i<IMAGE_IDS.length;i++)
{
// This will create dynamic image view and add them to ViewFlipper
ImageView image = new ImageView(getApplicationContext());
image.setBackgroundResource(IMAGE_IDS[i]);
flipper.addView(image);
}


gallery=(Gallery)findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(this));

if(mFlipping==0){
/** Start Flipping */
flipper.startFlipping();
mFlipping=1;
//mButton.setText(R.string.str_btn_stop);
}
else{
/** Stop Flipping */
flipper.stopFlipping();
mFlipping=0;
// mButton.setText(R.string.str_btn_start);
}

}


public class ImageAdapter extends BaseAdapter
{
int mGalleryItemBackground;
private Context mContext;

public ImageAdapter(Context c)
{
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Theme);
mGalleryItemBackground = a.getResourceId(
R.styleable.Theme_android_galleryItemBackground,0);
a.recycle();
}

public int getCount()
{
return IMAGE_IDS.length;
}

public Object getItem(int position)
{

return position;
}

public long getItemId(int position)
{
return position;


}

public View getView(int position,View convertView, ViewGroup parent)
{
ImageView i = new ImageView(mContext);
i.setImageResource(IMAGE_IDS[position]);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);

return i;
}
}

public void onClick(View v) {

finish();
android.os.Process.killProcess(android.os.Process.myPid());
}

最佳答案

如果我理解您的问题...我认为您需要使用 setOnItemSelectedListener...

gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> adapter, View gallery,
int position, long arg3) {

myPosition = position;
//tell your flipper something useful here using the current position of the gallery

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}
});

然后在 onItemSelected 回调中与你的脚蹼对话。

关于Android viewflipper 和画廊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13137256/

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