Java Android网格视图布局与优化
我有两个问题,第一个问题是,我正在创建一组gridview,gridview项目只是一个imageview,当我在项目中放置一个500*1000的图像(我只有四个项目)时,它会像疯了一样滞后,但如果我插入一个低分辨率的图片(100*200),它工作正常。所以android不能处理这个问题吗?(我也用过视图回收) 第二个问题是,我希望gridview项的宽度为125dp,垂直和水平间距为2dp,如果有额外的空间,我希望它拉伸gridview项,我在xml中为我的grid view项使用以下代码:Java Android网格视图布局与优化,java,android,xml,Java,Android,Xml,我有两个问题,第一个问题是,我正在创建一组gridview,gridview项目只是一个imageview,当我在项目中放置一个500*1000的图像(我只有四个项目)时,它会像疯了一样滞后,但如果我插入一个低分辨率的图片(100*200),它工作正常。所以android不能处理这个问题吗?(我也用过视图回收) 第二个问题是,我希望gridview项的宽度为125dp,垂直和水平间距为2dp,如果有额外的空间,我希望它拉伸gridview项,我在xml中为我的grid view项使用以下代码:
<?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>
只需将属性numColumns添加到xml格式的gridview中即可
android:numColumns="2"
有关更多详细信息,请阅读以下链接:-
Gridview的布局代码正常,更改
grid\u项
如下布局
<?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>
如果平板电脑正在使用它,我不希望它是2行,因此我希望图像宽度相同,并且numrows保持动态。当您必须进行平板电脑布局时,将其设置为numrows=2仍然没有帮助,可能是因为项目xml我应该使用matchparent作为宽度和高度?numcolumns抱歉typo@user3469274在imageview xml上,您编写了wrape content,只是去掉了columnwidth属性,仍然得到了完全相同的结果。那么,我的第一个问题的答案是什么?android不能处理高分辨率图片吗?@user3469274:u r缺少scaleType
和adjustViewBounds
属性。但最好使用不同分辨率的图像,并将这些图像放在不同的可绘制文件夹中