简体   繁体   English

Android - 带有通用图像加载器中另一个视图的ImageView

[英]Android - ImageView with Another Views in Universal Image Loader

I been struggling right now to customize the such that I can include another types of views in the gridview(Image). 我一直在努力定制,以便我可以在gridview(Image)中包含其他类型的视图。 I want to achieve the layout below but in the Universal Image Loader it only displays images. 我想实现下面的布局,但在Universal Image Loader中它只显示图像。 Any experience with this? 有这方面的经验吗?

在此输入图像描述

Xml: XML:

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/image"
    android:layout_width="fill_parent"
    android:layout_height="120dip"
    android:adjustViewBounds="true"
    android:contentDescription="@string/descr_image"
    android:scaleType="centerCrop" />

JAva JAVA

public View getView(int position, View convertView, ViewGroup parent) {
            final ImageView imageView;
            if (convertView == null) {
                imageView = (ImageView) getLayoutInflater().inflate(R.layout.item_grid_image, parent, false);
            } else {
                imageView = (ImageView) convertView;
            }

            imageLoader.displayImage(imageUrls[position], imageView, options);



            return imageView;
        }

I tried this code but it's not working. 我试过这段代码,但它没有用。 Basically I wanted to have the layout above. 基本上我想要上面的布局。

XML XML

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_x="201px"
android:layout_y="165px"
android:gravity="center_horizontal"
>
<ImageView 
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="120dip"
android:adjustViewBounds="true"
android:contentDescription="@string/descr_image"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/icon_text"
android:typeface="serif"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textStyle="bold"
android:lines="2">
</TextView>
</LinearLayout>

Java Java的

 public View getView(final int position, View convertView, ViewGroup parent) {
        View view = convertView;
        final ViewHolder holder;
        if (convertView == null) {
            view = getLayoutInflater().inflate(R.layout.item_grid_image, parent, false);
            holder = new ViewHolder();
            holder.text = (TextView) view.findViewById(R.id.icon_text);
            holder.image = (ImageView) view.findViewById(R.id.image);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.text.setText(album[position].getName());

        imageLoader.displayImage(albumsPhoto[position], holder.image, options, animateFirstListener);

        return view;
    }

ViewHolder is a custom class which is not part of Android SDK. ViewHolder是一个自定义类,不属于Android SDK。 It holds other views like TextView, ImageView and so many. 它包含其他视图,如TextView,ImageView等等。 This class can be used in ListView where Adapter is used. 此类可以在ListView中使用,其中使用了Adapter。 Read More to know more about Holder. 阅读更多以了解有关Holder的更多信息。

As you have layout, following can be your ViewHolder class structure. 由于您有布局,以下可以是您的ViewHolder类结构。

static class ViewHolder {
    public TextView text;
    public ImageView image;
}

You can see that, there is TextView and ImageView in ViewHolder . 您可以看到, ViewHolderTextViewImageView You need to define such many views as your custom_list_item layout has. 您需要像custom_list_item布局一样定义这么多视图。

Read -> ViewHolder Pattern – Caching View Efficiently 读取 - > ViewHolder模式 - 高效缓存视图

Layout 布局

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

<RatingBar
    android:id="@+id/ratingBar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/linearLayout1" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_alignRight="@+id/ratingBar1"
    android:layout_height="100dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:scaleType="fitXY"
    android:src="@drawable/ic_launcher" />

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/imageView1"
    android:layout_below="@+id/imageView1" >

    <TextView
        android:id="@+id/text1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="left"
        android:text="text1" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="right"
        android:text="text2" />
</LinearLayout>

</RelativeLayout>

Hi Universal Image Loader is an example for gallery view. Hi Universal Image Loader是图库视图的示例。 In order to achieve the above layout . 为了实现上述布局。 You need view Holder class and an adapter ,, LIstadapter. 您需要查看Holder类和适配器,LIstadapter。 You can list you images in list adapter and use ViewHolder for Image and Subtitle. 您可以在列表适配器中列出图像,并使用ViewHolder for Image和Subtitle。 The MosT important thing will be bitmap crashing if you are loading lot of Images ,, so each tiem you scroll Do delete teh cache mem for Bit maps. 如果您要加载大量图像,那么MosT重要的是位图崩溃,因此您滚动的每个tiem都会删除位图的缓存内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM