如何在android中显示带有名称的图像
您好,在我的应用程序中,我正在使用滑动显示图像。现在,我想在我想显示名称的图像下显示 我想在图像中写下一些名字。如何写代码 谁能帮帮我吗 照片类更新代码如何在android中显示带有名称的图像,android,Android,您好,在我的应用程序中,我正在使用滑动显示图像。现在,我想在我想显示名称的图像下显示 我想在图像中写下一些名字。如何写代码 谁能帮帮我吗 照片类更新代码 public class Photos extends Activity { Button button1; String mImages; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedIn
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>
对应的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>
你只需要用topTextView
和CenterImageView
包装一个布局,然后在你的实例化Item(…)
方法中膨胀该布局,并在其上设置不同的值……如何设置值从数组中提取值作为位置,然后设置到你的视图。就像我说的imageView.setImageResource(mImages[position])
和TextView
liketext\u View.setText(mText[position])代码>如果我正在创建数组,它将显示error@j那是什么?post iti我想创建新的xml?所以创建它,我只提供了您可以在这里编写imageView.setImageResource(mImages[position])代码>你好,尼廷·米斯拉,你能告诉我你可以在那里写imageView.setImageResource(mImages[position])代码>通过删除imageloader
行
<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>