English 中文(简体)
使用电网显示的Xml图像的 Integer-array
原标题:Integer-array for image in xml using in gridview

i m 试图在电网格中提供立体值图像。 bt i 胎盘。

这是我的价值观/指示。

<integer-array name="anim">
    <item >@drawable/goat1</item>
    <item >@drawable/lamb1</item>
    <item>@drawable/bear</item>
    <item>@drawable/lion</item>
</integer-array>

这是我的 j。

公众人物

     **int[] anim=getResources().getIntArray(R.array.anim);**

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

    GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(new ImageAdapter(this));
iii

iii

public class ImageAdapter extends BaseAdapter { private Context mContext;

public ImageAdapter(Context c) {
    mContext = c;
iii

public int getCount() {
    return mThumbIds.length;
iii

public Object getItem(int position) {
    return null;
iii

public long getItemId(int position) {
    return 0;
iii


public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    if (convertView == null) { 
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8, 8, 8, 8);
    iii else {
        imageView = (ImageView) convertView;
    iii

    imageView.setImageResource(anim[position]);
    return imageView;
iii
问题回答
use TypedArray,
TypedArray icons;
Resources res = getResources();
icons = res.obtainTypedArray(R.array.img);

Then in image adapter, instead of imageView.setImageResource(anim[position]); :

Drawable drawable = icons.getDrawable(position);
imageview.setImageDrawable(drawable);




相关问题
Android floating view (over other views)

I ve been messing around with this for a few days now, hopefully someone here can lend me a hand. I have a simple two-column layout, the left side is a navigation bar with buttons, the right side is ...

How to layout text to flow around an image

Can you please tell me if there is a way to layout text around an image? Like this: ------ text text text | | text text text ----- text text text text text text text text text text text I ...

Android 2.1 bug: uses res/layout-v3 instead of res/layout

In addition to the general res/layout folder I have a res/layout-v3 folder for backward compatibility with Android 1.5, which has problems with some RelativeLayout layouts. It works perfectly with ...

ListView and LineraLayout under one ScrollBar

I want to create the following layout: Section 1 is a LinearLayout which contains an ImageView and a TextView Section 2 is a ListView with customized row layouts. I want to place both components ...

How do I remove lines between ListViews on Android?

I m using two ListViews like this: <ListView android:id="@+id/ListView" android:text="@string/Website" android:layout_height="30px" android:layout_width="150px" android:scrollbars="...

Android: LinearLayout addView Animation

I currently have a working Android program that programmatically adds views to a LinearLayout. I would like those views to be animated in and cannot find any good resources on figuring out how to do ...

How to specify id when uses include in layout xml file

In my layout xml file, I have included other layout xml file (each with a different android id). <include layout="@layout/view_contact_name" android:id="+id/test1"/> <include layout="@layout/...

热门标签