我有以下xml实现,但我想使图像更大和更正方形。对不起,如果我的问题很简单,请考虑我在Android开发上开始了几周。
Grid.xml
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:numColumns="2"/>
GridItem.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_gravity="bottom"
android:textColor="@android:color/white"
android:background="#55000000"/>
</FrameLayout>
如果需要,这是我的适配器类代码:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.grid_item, parent, false);
}
NetworkImageView imageView = (NetworkImageView) convertView.findViewById(R.id.picture);
TextView textView = (TextView) convertView.findViewById(R.id.text);
ImageRecord imageRecord = getItem(position);
imageView.setImageUrl(imageRecord.getUrl(),mImageLoader);
textView.setText(imageRecord.getTitle());
return convertView;
}
答案 0 :(得分:0)
首先为NetworkImageView
设置固定尺寸:
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/picture"
android:layout_width="120dp"
android:layout_height="120dp"
android:scaleType="centerCrop"/>