本文介绍了安卓:为什么没有对了maxHeight视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看的有了minHeight 但不知何故,缺乏一个了maxHeight

我试图做到的,是有一些项目(视图)填补了一个滚动型。当有1..3项目我想直接显示出来。含义滚动型有一个1,2或3个项目的高度。

What I'm trying to achieve is having some items (views) filling up a ScrollView. When there are 1..3 items I want to display them directly. Meaning the ScrollView has the height of either 1, 2 or 3 items.

当有4个或更多的项目我想滚动型停止扩张(因而了maxHeight ),并开始提供滚动。

When there are 4 or more items I want the ScrollView to stop expanding (thus a maxHeight) and start providing scrolling.

然而,不幸的是没有办法设置一个了maxHeight 。所以,我可能要编程设置我的滚动型高度为 WRAP_CONTENT 当有1..3项目和设置高度 3 *整型尺寸(查看)时,有4个或更多的项目。

However, there is unfortunately no way to set a maxHeight. So I probably have to set my ScrollView height programmatically to either WRAP_CONTENT when there are 1..3 items and set the height to 3*sizeOf(View) when there are 4 or more items.

谁能解释为什么没有了maxHeight 规定,如果已经有一个了minHeight

Can anyone explain why there is no maxHeight provided, when there is already a minHeight?

(BTW:一些观点,如的ImageView 有一个了maxHeight 实施。)

(BTW: some views, like ImageView have a maxHeight implemented.)

推荐答案

所有这些解决方案的工作是什么,我需要这是一个滚动型设置为WRAP_CONTENT但有一个了maxHeight,因此将停止某一点后扩大,并开始滚动。我只是单纯地推翻,滚动型的onMeasure方法。

None of these solutions worked for what I needed which was a ScrollView set to wrap_content but having a maxHeight so it would stop expanding after a certain point and start scrolling. I just simply overrode the onMeasure method in ScrollView.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(300, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

这可能不是在所有情况下都有效,但它肯定给了我需要我的布局的结果。而且这还解决了评论意见马杜。

This might not work in all situations, but it certainly gives me the results needed for my layout. And it also addresses the comment by madhu.

如果一些布局present滚动视图下方则这一招不会工作 - 马杜3月5日在4:36

这篇关于安卓:为什么没有对了maxHeight视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 13:38