【发布时间】:2015-12-06 01:01:49
【问题描述】:
问题图片:http://i.imgur.com/pYLFMnO.png
我有一个网格视图,其中有我的HomeViewShortcutItemViews。
在我的HomeViewShortcutItemView onMeasure 中,我将其设为正方形:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
setMeasuredDimension(width, width); /* make grid item square */
}
在我的这个视图的 xml 中,我将高度设置为 match_parent:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue"
>
...
</RelativeLayout>
但是它在网格视图项中呈现它的wrap_content 高度,因为 onMeasure 不会影响它的子视图,而是让它按照我的意愿变成正方形。
我怎样才能实现我想要的?
顺便说一下,这里是 GridView Xml:
<pe.kor.browser.Ui.TabView.HomeView.StaticGridView
android:id="@+id/gridViewShortcuts"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:listSelector="@drawable/view_home_shortcut_item_bg"
android:stretchMode="columnWidth"
android:verticalSpacing="4dp"
android:horizontalSpacing="4dp"
/>
【问题讨论】:
标签: android