StackView怎么在Android中使用

  介绍

今天就跟大家聊聊有关StackView怎么在Android中使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

<强>一、直接闪退,然后报错。一般会有头这么一句话:

未能分配74649612字节分配16765728字节和59个mb自由直到伯父

提示一个很明白了,内存溢出,具体原因是关于Android的内存分配机制的这里就不详细讲了

这不经事StackView常见的问题,所有添加图片的活动都可能发生

怎么办呢?主要有两种办法:

1。暴力直接,用图片转换器(或者直接用windows自带画图工具)将图进行压缩。但很明显治标不治本。

2。将图片转为位图,然后再将其质量和大小进行压缩。

<强>二,加完图片后发现图片不显示

这个一般来说是代码本身的问题

检查下你列表对象和适配器对象的一些名字是否一致

这里以MainActivity为例(改编自疯狂Android)

public  class  MainActivity  extends  Activity  {   StackView 才能;StackView ;   int[],才能imageIds =, new  int [] {   ,,,,,,R.drawable.a0 R.drawable.a00, R.drawable.a1, R.drawable.a02,   ,,,,,,R.drawable.a1 R.drawable.a2, R.drawable.a3   ,,};   @Override才能   protected 才能;void  onCreate (Bundle  savedInstanceState), {   ,,,super.onCreate (savedInstanceState);   ,,,setContentView (R.layout.activity_main);   ,,,stackView =, (StackView), findViewById (R.id.mStackView);   ,,,//创建一个list 对象,元素是地图   ,,,List祝辞listItems =,,,,,,,new  ArrayList在();   ,,,(,int 小姐:=,0,,,小姐:& lt;, imageIds.length ;,我+ +,){   ,,,,,Map<字符串,Object>, listItem =, new  HashMap<字符串,Object> ();   ,,,,,listItem.put (“image", imageid[我]);   ,,,,,listItems.add(列);   ,,,}   ,,,//创建一个Simple 适配器   ,,,SimpleAdapter  SimpleAdapter =, new  SimpleAdapter(这一点,   ,,,,,,,listitem,   ,,,,,,,R.layout.photo,   ,,,,,,,new  String [] {“image"},   ,,,,,,,new  int [] {R.id.image1});   ,,,stackView.setAdapter (simpleAdapter);   ,,}   public 才能;void 上一页(View 源){   ,,,//显示上一个组件   ,,,stackView.showPrevious ();   ,,}   public 才能;void  next (View 源){   ,,,//显示下一个组件   ,,,stackView.showNext ();   ,,}   }

注意检查一下listitem和simpleAdapter用来存放图片的变量名是否一致

比如我这儿是叫做图片

这是比较常见的一种错误,如果是其他错误则需要大家再去谷歌一下了

鉴于很多同学表示不知道细胞(我这里叫做图)这个布局是什么

其实就是一个很简单的布局向自定义listView等等,很多时候都得用上这种自定义的布局

& lt; ? xml  version=?.0“,编码=皍tf-8" ?比;   LinearLayout & lt;   ,,xmlns: android=癶ttp://schemas.android.com/apk/res/android"   android:才能layout_width=皐rap_content"   android:才能layout_height=皐rap_content"比;   & lt; ImageView才能   ,,,android: id=癅 + id/image1"   ,,,android: layout_width=?00 dp"   ,,,android: layout_height=?00 dp"   ,,,android: scaleType=癴itXY"   ,,,android: layout_gravity=癱enter"/比;   & lt;/LinearLayout>

我遇到的坑大概就这些了,最后附上布局文件:

& lt; ? xml  version=?.0“,编码=皍tf-8" ?比;   & lt; RelativeLayout  xmlns: android=癶ttp://schemas.android.com/apk/res/android"   xmlns:才能应用=癶ttp://schemas.android.com/apk/res-auto"   xmlns:才能工具=癶ttp://schemas.android.com/tools"   android:才能id=癅 + id/container"   android:才能layout_width=癿atch_parent"   android:才能layout_height=癿atch_parent"   android:才能取向=皏ertical"   工具:才能上下文=?MainActivity"祝辞   & lt; StackView才能   ,,,android: id=癅 + id/mStackView"   ,,,android: layout_width=癿atch_parent"   ,,,android: layout_height=皐rap_content"   ,,,android: loopViews=皌rue"/比;   ,& lt; LinearLayout   ,,,android: layout_width=癿atch_parent"   ,,,android: layout_height=皐rap_content"   ,,,android: layout_alignParentBottom=皌rue"   ,,,android:重力=癱enter_horizontal"   ,,,android:取向=癶orizontal"比;   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

StackView怎么在Android中使用