【问题标题】:linear layout or scrollview getting pushed off the screen线性布局或滚动视图被推离屏幕
【发布时间】:2014-07-16 18:16:50
【问题描述】:

由于某种原因,滚动视图被推离屏幕

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_new_male_female_sf"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal" >

<RelativeLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_weight="2" >

    <RelativeLayout
        android:id="@+id/rel_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

     //DYNAMICALLY PUTTING IMAGEVIEW HERE   

    </RelativeLayout>

    <Button
        android:id="@+id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

<ScrollView
    android:id="@+id/scrollview"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_weight="3" >

    <LinearLayout
        android:id="@+id/selection_bar"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

    </LinearLayout>

</ScrollView>

</LinearLayout>

我尝试将最外层布局设为相对布局,但随后滚动视图与嵌套的相对布局重叠。谁能给个建议?

【问题讨论】:

    标签: android view scrollview android-linearlayout off-screen


    【解决方案1】:

    它不起作用,因为您使用 match_parent 作为高度,所以 RelativeLayout 占据了所有空间。当总和大于LinearLayout时,权重用于分配剩余的空白空间或带走空间。

    将宽度设置为 0dp 即可。 :)

    【讨论】:

    • 我试过了,还是不行。我刚刚删除了按钮,事情成功了。但是感谢您的回复,非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多