[英]Android GridView layout and optimization
我有两个问题,第一个问题是我正在创建一堆gridviews,并且gridview项目只是一个imageview,当我在项目中放置500 * 1000图像(我只有四个项目)时,它会像疯了似的滞后,但是如果我插入一个较低的分辨率图片(100 * 200),它工作正常。 android不能处理这个吗?(我也使用过视图回收)
第二个是我希望我的gridview项宽为125dp,垂直和水平间距为2dp,如果有多余的空间,我希望它可以拉伸gridview项,那么我将在xml中使用此代码作为网格查看项目:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:id="@+id/imageView_icon"
android:layout_height="wrap_content" >
</ImageView>
和我的GridView:
<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:verticalSpacing="2dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:stretchMode="columnWidth"
android:scrollbars="none"
android:columnWidth="125dp"
android:horizontalSpacing="2dp"
android:numColumns="auto_fit" >
</GridView>
这就是我要的:
这就是我得到的:
这样尝试
<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:verticalSpacing="2dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:stretchMode="columnWidth"
android:scrollbars="none"
android:horizontalSpacing="2dp"
android:numColumns="2" >
</GridView>
只需在xml的gridview上添加numColumns属性即可。
android:numColumns="2"
有关更多详细信息,您必须阅读以下链接:-
http://developer.android.com/guide/topics/ui/layout/gridview.html
Gridview的布局代码可以,更改像这样的grid_item
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/hello_world"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:cropToPadding="false" />
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.