android gridview的item是正方形 10
gridview的属性如下:<GridViewandroid:id="@+id/gv_group_chat_images"android:layout_width="ma...
gridview的属性如下:
<GridView
android:id="@+id/gv_group_chat_images"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/navigation_Bar"
android:horizontalSpacing="4dp"
android:numColumns="4"
android:stretchMode="columnWidth"
android:verticalSpacing="4dp" />
item的layout如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#aaa" >
<com.weijuba.widget.NetImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
效果图如下:
我想要每个item都是正方形,每排四个排好,为啥死活不行,无论怎么设置都是扁的? 展开
<GridView
android:id="@+id/gv_group_chat_images"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/navigation_Bar"
android:horizontalSpacing="4dp"
android:numColumns="4"
android:stretchMode="columnWidth"
android:verticalSpacing="4dp" />
item的layout如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#aaa" >
<com.weijuba.widget.NetImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
效果图如下:
我想要每个item都是正方形,每排四个排好,为啥死活不行,无论怎么设置都是扁的? 展开
1个回答
2015-08-24
展开全部
自定义Layout
public class SquareLayout extends RelativeLayout {
public SquareLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SquareLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareLayout(Context context) {
super(context);
}
@SuppressWarnings("unused")
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));
// Children are just made to fill our space.
int childWidthSize = getMeasuredWidth();
int childHeightSize = getMeasuredHeight();
//高度和宽度一样
heightMeasureSpec = widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询