根据屏幕大小,我想动态设置RelativeLayout 的高度。另一种方法是使用 setMinimumHeight() 但我仍然想知道为什么会崩溃。
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder vh;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.question_row_inflater, null);
vh = new ViewHolder(); // will store references to views
vh.answerBlock = (RelativeLayout) convertView.findViewById(R.id.answerBlock);
convertView.setTag(vh); // store vh away
} else {
vh = (ViewHolder) convertView.getTag();
}
int height = mRes.getDisplayMetrics().heightPixels;
// workaround for small screens
if (height < 490)
RelativeLayout.LayoutParams par = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 30);
vh.answerBlock.setLayoutParams(par);
}
return convertView;
}
这是类广播异常:
<RelativeLayout
android:id="@+id/answerBlock"
android:layout_width="fill_parent"
android:layout_height="@dimen/list_height"
android:layout_weight="1"
android:clickable="true"
android:paddingLeft="16dp" >
<TextView
android:id="@+id/answerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>