【问题标题】:scrollview and linearlayout weird view [duplicate]滚动视图和线性布局奇怪的视图[重复]
【发布时间】:2012-04-05 17:01:45
【问题描述】:

可能重复:
How can I put a ListView into a ScrollView without it collapsing?

我正在尝试将食物菜单设置为可滚动的,但是一旦我添加它,它就会变成图像中的样子。在我添加滚动视图之前,我无法在屏幕上查看我的后退按钮,即使我已经添加了它。这是我奇怪的代码。

<?xml version="1.0" encoding="utf-8"?>
 <ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/foodbg"
    android:orientation="vertical" >

        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:id="@+id/backToMenu"
            android:text="Back" >
        </Button>

</LinearLayout>

【问题讨论】:

  • 尝试修复 wrap_content 的按钮 instad
  • 移除scrollview并尝试使用listview的setFooter和不同的布局xml文件,那里有按钮。

标签: android android-layout


【解决方案1】:

您好,您可以使用 RelativeLayout 代替 LinearLayout。

在这种情况下,您应该将按钮放在布局的底部。之后将您的列表放在布局顶部和按钮上方。 RelativeLayout 具有特殊的 xml 属性来帮助您执行此操作。之后你就不需要 ScrollView。

【讨论】:

    【解决方案2】:
    <ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="bottom"
        android:orientation="vertical" >
    
            <ListView
                android:id="@android:id/list"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1" />
    
            <Button
                android:layout_width="fill_parent"
                android:layout_height="45dp"
                android:layout_gravity="bottom"
                android:id="@+id/backToMenu"
                android:text="Back" >
            </Button>
    
    </LinearLayout>
    </ScrollView>
    

    尝试实现以上代码

    【讨论】:

    • 不...不能工作。与图片中的情况相同
    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-25
    相关资源
    最近更新 更多