【问题标题】:Why doesn't my relative layout take whole screen height为什么我的相对布局不占用整个屏幕高度
【发布时间】:2013-02-21 10:16:41
【问题描述】:

所以,我有一些简单的布局,带有一些文本和一个按钮。文本在开始时定位,在某些手机上,高度高于屏幕高度,因此我将其定位在滚动视图中。在该文本旁边,我还有一个文本视图和一个按钮,该按钮应位于屏幕的右下角。问题是一个大屏幕我的按钮不在底部,而是在文本结束的地方,我可以看到我的 relativelayout 并没有占据 scrollView 的整个高度。我的布局:

<ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="Some dummy text"
        android:textColor="#969696"
        android:textSize="13dp" />




    <TextView
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="false"
        android:layout_below="@+id/text1"
        android:text="some dummy text2"
        android:textColor="#969696"
        android:textSize="13dp" />



    <ImageButton
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:src="@drawable/btn49_2x" />

</RelativeLayout>

</ScrollView>

我的真实布局有点复杂,所以我需要使用相对布局。但是如何确保它占据整个屏幕高度?

我尝试将高度设置为wrap:content,但没有效果。

【问题讨论】:

  • 为什么不直接设置 layout_height = "fill_parent" ?
  • 检查@idaNakav 的回答,它会解决你的问题。
  • 因为滚动视图,去掉滚动视图或者在滚动视图中添加android:fillViewport="true"
  • @ManmeetSinghBatra 你知道他为什么使用 ScrollView>
  • 有人能解释为什么投反对票吗?这是一个真正的问题,我没有看到它的任何副本,我得到了真正的答案。

标签: android scrollview android-relativelayout


【解决方案1】:

将android:fillViewport="true" 添加到您的 ScrollView

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-03
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    • 2019-09-21
    • 1970-01-01
    相关资源
    最近更新 更多