【问题标题】:Layout: bottom bar + scrollview over it that start from top布局:底部栏+滚动视图从顶部开始
【发布时间】:2012-03-23 23:41:33
【问题描述】:

我找不到解决方案。我设法解决了滚动视图不与底部的按钮+文本视图重叠的问题,但我仍然无法让滚动视图从屏幕顶部开始,而不是从按钮上方开始。

请注意,即使是底部的线性布局(按钮+文本视图)也不是我想要的。我找不到让所有东西都正确定位的方法。

Eclipse 也无济于事,因为 xml 的文本视图在我的鼠标下不断变化,使其非常烦人。我必须打开一个外部编辑器来编辑它。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top" >
<LinearLayout
    android:id="@+id/LinearLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true" >
    <TextView
        android:id="@+id/text_phrase"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="@string/play" />
</LinearLayout>
<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/LinearLayout2"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="18dp" >




    <LinearLayout
        android:id="@+id/layout_player_checkboxes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="top"
        android:orientation="vertical" >

        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="CheckBox" />
    </LinearLayout>

</ScrollView>

【问题讨论】:

  • 你能告诉我你希望你的布局如何,否则图像会很棒
  • 我看到的新stackoverflow不允许我轻松编辑:(我希望你能看到这个链接:i.imgur.com/RaOLE.png这是我想要的,但是通过上面的代码,我得到了三个“Heading3”锚定到下面的线性布局,而不是如图所示锚定到顶部。
  • 好的,所以你想要这样的东西,标题的数量限制为三个,否则它将是动态的
  • 这是一个滚动视图,带有一个充满复选框的线性布局。它们可以是从 1 到 20 甚至更多的任何数字。这就是我使用滚动视图的原因。

标签: android eclipse layout


【解决方案1】:

如果您将android:layout_alignParentTop="true"android:layout_weight="1" 添加到您的滚动视图中,同时保留您已有的其他内容,它应该从顶部开始并填充下面的屏幕,直到出现线性布局2。 (如果您决定按照 rajesh.adhi 的建议切换到列表视图,同样适用)

哦,你好像也错过了&lt;/RelativeLayout&gt;

【讨论】:

  • 权重仅适用于线性布局。它被相对布局忽略。不过,AlignParentTop 应该可以解决问题。
  • Doh。我在想他将滚动视图包裹在线性布局中,在这种情况下它会产生效果。感谢您指出我的错误。
  • 我想我试图将滚动视图包装在线性布局中,但结果是滚动视图与底部的按钮和文本重叠。
  • 那么,android:layout_alignParentTop="true" 为您解决了吗?如果是,请单击复选标记以接受答案,以便所有人都知道问题已解决。
  • 将 alignParentTop 设置为 true 似乎可以解决问题。 Rajesh 看起来不错,但我不认为我必须改变一切来实现我想要的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-14
  • 1970-01-01
  • 1970-01-01
  • 2014-06-05
  • 2018-05-07
相关资源
最近更新 更多