嗨我在显示Gridview时遇到问题。我在StackOverflow上搜索了很多站点,但是花了几天没有找到解决方案。
我在这里留下我的xml(listado.xml)代码,其中是gridview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<GridView
android:id="@+id/grid_release"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipChildren="true"
android:stretchMode="columnWidth"
android:numColumns="2"
>
<!-- android:stretchMode="columnWidth"
android:stretchMode="spacingWidthUniform"
android:verticalSpacing="1dip"-->
</GridView>
带有textview和imageview(grid_release.xml)的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#DC0000"
android:orientation="vertical"
android:gravity="center_horizontal" >
<ImageView
android:id="@+id/rls_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/rls_txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Titulo" />
同时保留ImageAdapter的代码:
public View getView(int position, View convertView, ViewGroup parent) {
View grid;
if(convertView==null)
{
grid = new View(context);
grid = layoutInflater.inflate(R.layout.grid_release, null);
}else{
grid = (View)convertView; //imageView=(ImageView)convertView;
}
ImageView rlsimg = (ImageView)grid.findViewById(R.id.rls_img);
rlsimg.setImageDrawable(LoadImageFromURL(GridViewConfig.getResim_list().get(position)));
TextView rsltxt = (TextView)grid.findViewById(R.id.rls_txtTitle);
rsltxt.setText("Adpt00"+position);
return grid;
感谢您的帮助!!!
答案 0 :(得分:0)
这解决了我的问题:
ImageAdapter的Metodo GetView
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View myView;
if(convertView==null)
{
LayoutInflater li = ((Activity)context).getLayoutInflater();
myView = li.inflate(R.layout.grid_prueba1, null);
myView.setLayoutParams(new GridView.LayoutParams(100,100));
myView.setPadding(5,5,5,5);
}else{
myView = (View)convertView;
}
ImageView img = (ImageView)myView.findViewById(R.id.img2);
img.setImageDrawable(LoadImageFromURL(GridViewConfig.getResim_list().get(position)));
TextView txt = (TextView)myView.findViewById(R.id.txt2);
txt.setText("Adept0000"+position);
return myView;
}
但现在我还有另一个问题,图像中显示的是textview。我希望这个文字在图像下面。我将不得不打开另一个查询。