如何显示在Android的名称图像 [英] how to display the image with name in android

查看:161
本文介绍了如何显示在Android的名称图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜在我的应用我用swipe.Now显示图像,我想我要显示的名称根据图像显示。

我想在image.how写一些名字写code
任何人都可以请帮助我。

照片类更新code

 公共类照片扩展活动{    按钮按钮1;
    串mImages;      公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.photos);        ViewPager viewPager =(ViewPager)findViewById(R.id.view_pager);
        ImagePagerAdapter适配器=新ImagePagerAdapter();
        viewPager.setAdapter(适配器);
      }      私有类ImagePagerAdapter扩展PagerAdapter {          的String [] = description_images getIntent()getExtras()getStringArray({此搜索,图像2,图像3,图像4})。; //关联图像的所有文字ARRAY
          的String [] = mImages getIntent()getExtras()getStringArray({R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d})。;
       //的String [] =多行文字{文本1,文本2​​,文本3};        @覆盖
        公众诠释的getCount(){
          返回mImages.length;
        }        @覆盖
        公共布尔isViewFromObject(查看视图,Object对象){
          返回查看==((ImageView的)对象);
        }        @覆盖
        公共查看instantiateItem(ViewGroup中的容器,INT位置){
            LayoutInflater充气= LayoutInflater.from(container.getContext());
            查看查看= inflater.inflate(R.layout.image_view,NULL);
            最后ImageView的ImageView的=(ImageView的)view.findViewById(R.id.iv_image);
            最终的TextView的TextView =(TextView中)view.findViewById(R.id.iv_text);            textView.setText(description_images [位置]);
           // imageView.setImageResource(mImages [位置]);
            container.addView(视图,0);
            返回视图。
        }        @覆盖
        公共无效destroyItem(ViewGroup中的容器,INT位置,Object对象){
            container.removeView((查看)对象);
        }
    }
}

XML

 < android.support.v4.view.ViewPager
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / view_pager
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:layout_alignParentLeft =真
    机器人:layout_alignParentTop =真
    机器人:背景=#000000>< /android.support.v4.view.ViewPager>


解决方案

  description_images = getIntent()getExtras()getStringArray(images_name)。; //关联图像的所有文字ARRAY
    mImages = getIntent()getExtras()getStringArray(images_path)。。 //阵列中的所有图像路径私有类ImagePagerAdapter扩展PagerAdapter {
        @覆盖
        公众诠释的getCount(){
            返回mImages.length;
        }        @覆盖
        公共布尔isViewFromObject(查看视图,Object对象){
            返回查看==对象;
        }        @覆盖
        公共查看instantiateItem(ViewGroup中的容器,INT位置){
            LayoutInflater充气= LayoutInflater.from(container.getContext());
            查看查看= inflater.inflate(R.layout.image_view,NULL);
            最后ImageView的ImageView的=(ImageView的)view.findViewById(R.id.iv_image);
            最终的TextView的TextView =(TextView中)view.findViewById(R.id.iv_text);            textView.setText(description_images [位置]);
            imageLoader.displayImage(mImages [位置],ImageView的,期权);
            container.addView(视图,0);
            返回视图。
        }        @覆盖
        公共无效destroyItem(ViewGroup中的容器,INT位置,Object对象){
            container.removeView((查看)对象);
        }
    }

相应的XML

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>    < ImageView的
        机器人:ID =@ + ID / iv_image
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent/>    <的TextView
        机器人:ID =@ + ID / iv_text
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:layout_alignParentBottom =真/>< / RelativeLayout的>

Hi In My application I am displaying images by using swipe.Now, i want to display the under the image i want to display the name.

I want to write the some name in that image.how to write the code Can anyone please help me.

Photos class updated code

    public class Photos extends Activity {

    Button button1;  
    String mImages;

      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photos);

        ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
        ImagePagerAdapter adapter = new ImagePagerAdapter();
        viewPager.setAdapter(adapter);
      }

      private class ImagePagerAdapter extends PagerAdapter {

          String[] description_images = getIntent().getExtras().getStringArray("{image1,image2,image3,image4}"); //ARRAY OF ALL TEXT ASSOCIATED TO IMAGES
          String[] mImages = getIntent().getExtras().getStringArray("{R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d}");  


       // String[] mText={"Text1","Text2","Text3"};

        @Override
        public int getCount() {
          return mImages.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
          return view == ((ImageView) object);
        }

        @Override
        public View instantiateItem(ViewGroup container, int position) {
            LayoutInflater inflater = LayoutInflater.from(container.getContext());
            View view = inflater.inflate(R.layout.image_view, null);
            final ImageView imageView = (ImageView)view.findViewById(R.id.iv_image);
            final TextView textView = (TextView )view.findViewById(R.id.iv_text);

            textView.setText(description_images[position]);
           // imageView.setImageResource(mImages[position]);
            container.addView(view, 0);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    }
}

xml

<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="#000000" >

</android.support.v4.view.ViewPager>

解决方案

    description_images = getIntent().getExtras().getStringArray("images_name"); //ARRAY OF ALL TEXT ASSOCIATED TO IMAGES
    mImages = getIntent().getExtras().getStringArray("images_path"); //ARRAY OF ALL IMAGE PATHS

private class ImagePagerAdapter extends PagerAdapter {
        @Override
        public int getCount() {
            return mImages.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public View instantiateItem(ViewGroup container, int position) {
            LayoutInflater inflater = LayoutInflater.from(container.getContext());
            View view = inflater.inflate(R.layout.image_view, null);
            final ImageView imageView = (ImageView)view.findViewById(R.id.iv_image);
            final TextView textView = (TextView )view.findViewById(R.id.iv_text);

            textView.setText(description_images[position]);
            imageLoader.displayImage(mImages[position], imageView, options);
            container.addView(view, 0);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    }

Corresponding XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/iv_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <TextView
        android:id="@+id/iv_text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

这篇关于如何显示在Android的名称图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆