如何实现一个view或者layout,使它有一个最大高度?也就是说
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/content_body"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ScrollView>
但是无论我怎么设置ScrollView和子layout的layout_width和layout_height属性都无法达到上面的要求。
public class AutoFitScrollView extends ScrollView {
private static final int MAX_HEIGHT = 300;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
View child = getChildAt(0);
child.measure(widthMeasureSpec, heightMeasureSpec);
int width = child.getMeasuredWidth();
int height = Math.min(child.getMeasuredHeight(), MAX_HEIGHT);
setMeasuredDimension(width, height);
}
}