【问题标题】:Android: FrameLayout squeezes ViewAndroid:FrameLayout 挤压 View
【发布时间】:2012-07-10 10:20:00
【问题描述】:

我正在使用以下布局:

FrameLayout 填充整个 Viewport,即宽度和高度设置为 MATCH_PARENT

RelativeLayout 的宽高设置为 WRAP_CONTENT

View1 到 View5 具有固定的尺寸,例如宽度 = 500,高度 = 50

View 5 位于 FrameLayout 的边框附近,被 Android 挤压, 使其完全位于 FrameLayout 中。 View5 的高度应该是 50 但不幸的是 Android 将其更改为较小的值。

如何避免 Android 改变 View5 的高度?

当我滚动RelativeLayout时,错误仍然存​​在。

此处描述了类似的行为: button is squeezed when it exceeds layout

【问题讨论】:

  • 不知道你为什么要用FrameLayout。相对布局就足够了。关于您的问题 - 尝试使用 android:minHeight=50dp 和 android:maxHeight=50dp。
  • 我同时使用这两种布局,因为我想在 FrameLayout 中滚动 RelativeLayout。 FrameLayout 只能有一个孩子。你的提议对我来说不清楚,方法 setMaximumHeight() 不存在。
  • minHeight 是 xml 参数。您可以在代码中使用 setMinimumHeight。 maxHeight 也存在,但在例如。 TextView 因此取决于您使用哪种视图,它也可以提供帮助(如果可用)。只尝试 minHeight 可能会有所帮助。
  • 我已经测试了 minHeight 但不幸的是它并没有解决问题。还有其他想法吗?

标签: android android-framelayout


【解决方案1】:

一个“更好”解决这个问题的方法是使用ScrollViewlike

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content" >
         <View
             android:id="@+id/view1"
             android:layout_width="match_parent"
             android:layout_height="50dp"
             android:layout_alignParentTop="true" />
         <View
             android:id="@+id/view2"
             android:layout_width="match_parent"
             android:layout_height="50dp"
             android:layout_below="@+id/view1" />
         <View
             android:id="@+id/view3"
             android:layout_width="match_parent"
             android:layout_height="50dp"
             android:layout_below="@+id/view2" />
 <!-- YOU GET THE IDEA -->

    </RelativeLayout> 
</ScrollView>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 2017-12-23
    • 1970-01-01
    • 2020-01-30
    • 2021-06-12
    • 1970-01-01
    相关资源
    最近更新 更多