android-如何在自定义列表视图中添加静态标题图像?

android-如何在自定义列表视图中添加静态标题图像?,第1张

概述我将图片放在标题图片的自定义列表视图之上,但是该图片是重复的,如何使它无法单击且不可重复?这是我的xml代码:<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apkes/android"android:layout_width="match_pa

我将图片放在标题图片的自定义列表视图之上,但是该图片是重复的,如何使它无法单击且不可重复?
这是我的xml代码:

    <?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="@color/abs__background_holo_light" >    <ImageVIEw        androID:ID="@+ID/detailimage"        androID:layout_wIDth="wrap_content"        androID:layout_height="140dp"        androID:layout_alignParentleft="true"        androID:layout_alignParentRight="true"        androID:layout_alignParenttop="true"        androID:contentDescription="@string/app_name"        androID:scaleType="centerCrop"        androID:src="@drawable/pantaigoacina" />    <relativeLayout        androID:ID="@+ID/detailLayout"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_below="@ID/detailimage"        androID:background="@color/abs__background_holo_light" >        <linearLayout            androID:ID="@+ID/thumbnail"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_marginleft="20dip"            androID:layout_marginRight="5dip"            androID:layout_margintop="20dip"            androID:background="@color/abs__background_holo_light"            androID:padding="5dip" >            <ImageVIEw                androID:ID="@+ID/List_image"                androID:layout_wIDth="15dip"                androID:layout_height="15dip"                 androID:src="@drawable/arrow"                androID:contentDescription="@string/app_name"/>        </linearLayout>        <TextVIEw            androID:ID="@+ID/NamaLokasi"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_aligntop="@+ID/thumbnail"            androID:layout_toRightOf="@+ID/thumbnail"            androID:text="Pantai Sipelot"            androID:textcolor="#040404"            androID:textSize="18sp"            androID:textStyle="bold"            androID:typeface="sans" />        <TextVIEw            androID:ID="@+ID/detailLokasi"            androID:layout_wIDth="fill_parent"            androID:layout_height="wrap_content"            androID:layout_below="@ID/NamaLokasi"            androID:layout_marginRight="20dip"            androID:layout_margintop="5dip"            androID:layout_toRightOf="@+ID/thumbnail"            androID:text="Deskripsi Konten, Lokasi Berada di Desa Wilayah Malang"            androID:textcolor="#343434"            androID:textSize="12sp" />    </relativeLayout></relativeLayout>

这是我的适配器:

String[] from = { "pantai", "detail" };int[] to = { R.ID.NamaLokasi, R.ID.detailLokasi };SimpleAdapter adapter = new SimpleAdapter(getActivity()        .getBaseContext(), aList, R.layout.fragment_detail, from,        to);setlistadapter(adapter);return super.onCreateVIEw(inflater, container, savedInstanceState);

解决方法:

从xml移除图像.

ImageVIEw iv = new ImageVIEw(getActivity());// set image to imagevIEwListVIEw List = getListVIEw();List.addheaderVIEw(headerVIEw);

该文档

public voID addheaderVIEw (VIEw v)Added in API level 1Add a fixed vIEw to appear at the top of the List. If addheaderVIEw is called more than once, the vIEws will appear in the order they were added. VIEws added using this call can take focus if they want.Note: When first introduced, this method Could only be called before setting the adapter with setAdapter(listadapter). Starting with KITKAT, this method may be called at any time. If the ListVIEw's adapter does not extend headerVIEwlistadapter, it will be wrapped with a supporting instance of Wrapperlistadapter.Parametersv   The vIEw to add.

编辑:

@OverrIDe    public voID onActivityCreated(Bundle savedInstanceStat)    {super.onActivityCreated(savedInstanceState);               List = getListVIEw();       ImageVIEw imageheaderVIEw = new ImageVIEw(getActivity());       imageheaderVIEw.setimageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.pantaigoacina));       List.addheaderVIEw(imageheaderVIEw);       List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();       for (int i = 0; i < DaerahWisata.pantai.length; i++) {               HashMap<String, String> hm = new HashMap<String, String>();               hm.put("pantai", DaerahWisata.pantai[i]);               hm.put("detail", "Lokasi : \r\n" + DaerahWisata.detailp[i]);               aList.add(hm);       }       String[] from = { "pantai", "detail" };       int[] to = { R.ID.NamaLokasi, R.ID.detailLokasi };       SimpleAdapter adapter = new SimpleAdapter(getActivity()                       .getBaseContext(), aList, R.layout.fragment_detail, from,                       to);                  setlistadapter(adapter);    }

编辑,如果要从其他xml布局设置imagevIEw:

List = getListVIEw();    Context context = getListVIEw().getContext();    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);    VIEw vIEw = inflater.inflate(R.layout.image_header, null);    List.addheaderVIEw(vIEw);
总结

以上是内存溢出为你收集整理的android-如何在自定义列表视图中添加静态标题图像?全部内容,希望文章能够帮你解决android-如何在自定义列表视图中添加静态标题图像?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1088644.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存