我创建了应用程序。这是在轮播视图中显示图像。我想单击轮播视图的图像并转到网站。
怎么做。我按以下方式将图像加载到我的轮播视图中。]
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private String[] data;
private static LayoutInflater inflater=null;
String dirUrl[];
public ImageLoader imageLoader;
public ViewGroup carousel;
HorizontalCarouselLayout carousel_layout_event;
int widthScreen,heightScreen;
public LazyAdapter(Activity a, String[] d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public void getDimensionScreen(int width,int height){
widthScreen=width;
heightScreen=height;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.showsmain, null);
ImageView image=(ImageView)vi.findViewById(R.id.imageView1);
imageLoader.DisplayImage(data[position], image);
int width = Double.valueOf(widthScreen*1.4).intValue();
int height = Double.valueOf(heightScreen*1.2).intValue();
imageLoader.getDimension(width, height);
return vi;
}
}
图像视图的布局是,
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:scaleType="fitXY"
android:layout_alignParentTop="true" />
我的轮播布局 xml 文件是,
<com.touchmenotapps.carousel.simple.HorizontalCarouselLayout
android:id="@+id/carousel_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/relativeLayout1"
android:layout_marginTop="@dimen/marginTopUserImagePlayeractivity" >
</com.touchmenotapps.carousel.simple.HorizontalCarouselLayout>
请立即给我答案,我被这个问题困住了。
谢谢.........
在这里,我按照以下方式在我的主要活动中设置轮播适配器,
public void displayHomeScreen(View v) {
inflatedView.setVisibility(View.INVISIBLE);
footerlayout.setVisibility(View.VISIBLE);
headerlayout.setVisibility(View.VISIBLE);
carousel_layout.setVisibility(View.INVISIBLE);
progressbar.setVisibility(View.VISIBLE);
layout.setVisibility(View.VISIBLE);
clickCountHome = clickCountHome + 1;
((ViewGroup) carousel_layout_home).removeAllViews();
UIStateManager.getInsatance().homeClickedUIChange();
RelativeLayout rLayout = (RelativeLayout) findViewById(R.id.relLayoutPlayerActivity);
Resources res = getResources(); // resource handle
Drawable drawable = res.getDrawable(R.drawable.loggedinscreen);
rLayout.setBackgroundDrawable(drawable);
if (clickCountHome >= 1 && xmlHome != null) {
new CountDownTimer(1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
progressbar.setVisibility(View.INVISIBLE);
layout.setVisibility(View.INVISIBLE);
}
}.start();
carousel_layout_home.setStyle(mStyle);
carousel_layout_home.setAdapter(adapterHome);
carousel_layout_home
.setOnCarouselViewChangedListener(new CarouselInterface() {
@Override
public void onItemChangedListener(View v, int position) {
positionHome = position;
v.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse(dirHome[0]));
startActivity(myWebLink);
return false;
}
});
}
});
在这里,我通过解析 xml 将 url 获取为 dirHome ......
你能给出答案吗?我做了上面的事情。但它并没有完美地工作............