我已经尝试了2天,但我不知道为什么我的gridView无法全宽显示,我试过,我试过,我试过......
我的眼睛即将成为魔鬼的眼睛。我没有时间尝试解决它了。请找我问题..
这是我的代码: 格:
gridLightMaster.setAdapter(new LightImageGridAdater(getActivity()
.getApplicationContext(), listLights, display.getWidth(),
display.getHeight()));
适配器:
import java.util.List;
import com.fptsoftware.iolaunchapp.LayoutDimmerLight;
import com.fptsoftware.iolaunchapp.Logger;
import com.fptsoftware.iolaunchapp.R;
public class LightImageGridAdater extends BaseAdapter {
private Context mContext;
List<EnLightItem> data;
private int mWidth, mHeight;
ViewHolder holder;
public LightImageGridAdater(Context ctx, List<EnLightItem> data, int width,
int height) {
this.mContext = ctx;
this.data = data;
this.mWidth = width;
this.mHeight = height;
}
public class ViewHolder {
ImageView img;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
@Override
public EnLightItem getItem(int position) {
// TODO Auto-generated method stub
return data.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@SuppressWarnings("deprecation")
@SuppressLint({ "InflateParams", "ViewHolder" })
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Log.d("size parent:", "" + parent.getHeight() + "," + parent.getY());
if (convertView == null) {
convertView = inflater.inflate(
R.layout.item_light_horizontal_list1, parent, false);
holder = new ViewHolder();
holder.img = (ImageView) convertView.findViewById(R.id.imgLight1);
holder.img.setBackgroundColor(Color.RED);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
ViewGroup.LayoutParams params = convertView.getLayoutParams();
params.width = mWidth / 3;
params.height = mHeight / 4;
convertView.setLayoutParams(params);
// GestureDetectorCoonvertView).gestureDetector = mDetector;
return convertView;
}
}
布局网格:
<GridView
android:id="@+id/gridMasterLight"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:stretchMode="columnWidth" />
要膨胀的布局:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imgLight1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />