我必须将应用程序的 UI 创建为存放杂志的架子。我正在使用自定义网格视图,网格元素由具有货架作为背景图像的杂志缩略图组成。
架子.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="4" >
</GridView>
</LinearLayout>
项目.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/grid">
<ImageView
android:id="@+id/imageView1"
android:layout_width="70dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="41dp"
android:src="@drawable/book1" />
</RelativeLayout>
图书馆活动.java
public class LibraryActivity extends Activity {
GridView grid = null;
ArrayList<Integer> image = new ArrayList<Integer>();
ImageView thumbnail;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.shelf);
image.add(R.drawable.book1);
image.add(R.drawable.book2);
image.add(R.drawable.book3);
image.add(R.drawable.book4);
System.out.println("before adapter");
grid = (GridView) findViewById(R.id.gridView1);
CustomAdapter adapter = new CustomAdapter(this, R.layout.item);
grid.setAdapter(adapter);
}
public class CustomAdapter extends BaseAdapter {
Context mContext = null;
int mitem = 0;
LayoutInflater mInflater = null;
public CustomAdapter(Context context, int item) {
this.mContext = context;
this.mitem = item;
this.mInflater = (LayoutInflater) context
.getSystemService(LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return image.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
System.out.println("****CHECKING 2**********");
convertView = mInflater.inflate(mitem, null);
System.out.println("****CHECKING 3**********");
thumbnail = (ImageView) convertView
.findViewById(R.id.imageView1);
System.out.println("****CHECKING 3**********");
}
thumbnail.setImageResource(image.get(position));
return convertView;
}
}
}
但是使用此代码仅显示带有杂志的架子。我想显示空架子来占据设备的整个屏幕。我怎样才能做到这一点??有没有其他方法可以实现货架?