2016-07-26 79 views
0

我尝试了各种布局属性的许多组合,但我无法像我想要的那样使其工作。Android布局:如何阻止“wrap_content”超出minHeight的另一个布局?

这是我的布局:

<RelativeLayout 
    android:id="@+id/signature_cntSummary" 
    android:layout_below="@+id/signature_cntHeader" 
    android:layout_width="match_parent" 
    tools:layout_height="100dp" 
    android:layout_height="wrap_content"> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/signature_cntInput" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:minHeight="200dp"> 
</RelativeLayout> 

现在我想实现的是“signature_cntInput”应至少200dp的高度,但 - 如果可能的话 - 应填写了由留下的可能是免费的屏幕空间如果该顶层布局的内容没有占用全部空间,则使用“signature_cntSummary”布局。 如果第一个布局的内容太多,它不应该将第二个布局推出屏幕,但可以滚动,以便底部布局的高度可以达到200dp。

也许这些照片可以很清楚的:

Image: bottom layout takes remaining space

Image: bottom layout is forced to min height and upper layout content becomes scrollable

我该怎么办呢?它甚至有可能吗?我跑出来的想法......

安德烈

回答

-1

Layout Code Here

上述布局样本可以帮助你。

+0

谢谢! 但并不完全是我想达到的......所以我编辑了我的问题,希望澄清这一点。底部布局应该保持在屏幕上的位置。如果上部布局中的内容较少,或者如果上部布局中的内容较多/较多,高度缩小至最小200dp,则只需展开至顶部即可。那上面的布局就变成可滚动的了。 –

+0

对不起,我不明白你的观点。现在我想你想要什么可能无法通过纯XML代码实现。我建议你重写onMeasure来控制上层布局的高度,确保屏幕至少有200dp的空间为较低的布局。 – Jake

+0

你是正确的,我主要做你的建议: '@覆盖 保护无效onMeasure(INT widthMeasureSpec,诠释heightMeasureSpec) { INT高= MeasureSpec.getSize(heightMeasureSpec); int mode = MeasureSpec.getMode(heightMeasureSpec); int newHeight = Math.max(height - height/2,height/2); super.onMeasure(widthMeasureSpec,MeasureSpec.makeMeasureSpec(newHeight,mode)); }' –

相关问题