1

我正在尝试创建一个布局,该布局在屏幕顶部有两个等宽的按钮,然后在其正下方有一个滚动视图。我在滚动视图中有一个 linearLayout,因为这是我动态创建 UI 元素的地方。

按钮定位正确,但我的滚动视图被隐藏或滚动视图内的线性布局被隐藏,我无法判断并且对布局了解不足,无法确定发生了什么。我究竟做错了什么?我在 LinearLayout 中创建了一个 TextView 占位符,以判断我是否可以看到任何内容并且它没有显示出来。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/EditRecordOuterLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:orientation="horizontal"
    >

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <RelativeLayout
            android:id="@+id/Bforeground"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center" >

            <TextView
                android:id="@+id/cancelButtonText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:textSize="20dp"
                android:text="Cancel" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toLeftOf="@id/cancelButtonText"
                android:paddingBottom="10dip"
                android:paddingTop="10dip"
                android:src="@drawable/cancel" />
        </RelativeLayout>
                    <Button
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_alignBottom="@id/Bforeground"
            android:layout_alignLeft="@id/Bforeground"
            android:layout_alignRight="@id/Bforeground"
            android:layout_alignTop="@+id/Bforeground"
            android:onClick="clickedMe"
            android:gravity="center" />
    </RelativeLayout>

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <RelativeLayout
            android:id="@+id/foreground"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center" >

            <TextView
                android:id="@+id/button_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:textSize="20dp"
                android:text="Save" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toLeftOf="@id/button_text"
                android:paddingBottom="10dip"
                android:paddingTop="10dip"
                android:src="@drawable/save" />
        </RelativeLayout>
                    <Button
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_alignBottom="@id/foreground"
            android:layout_alignLeft="@id/foreground"
            android:layout_alignRight="@id/foreground"
            android:layout_alignTop="@+id/foreground"
            android:onClick="clickedMe"
            android:gravity="center" />
    </RelativeLayout>
</LinearLayout>
<ScrollView
    android:id="@+id/editRecordScrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/editRecordLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
                     <TextView
                android:id="@+id/someText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:textSize="20dp"
                android:text="This text should be showing..." />
    </LinearLayout>
</ScrollView>

知道了!谢谢你们。固定版本如下。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/EditRecordOuterLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:orientation="horizontal"
        >

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >

            <RelativeLayout
                android:id="@+id/Bforeground"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center" >

                <TextView
                    android:id="@+id/cancelButtonText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:textSize="20dp"
                    android:text="Cancel" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_toLeftOf="@id/cancelButtonText"
                    android:paddingBottom="10dip"
                    android:paddingTop="10dip"
                    android:src="@drawable/cancel" />
            </RelativeLayout>
                        <Button
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_alignBottom="@id/Bforeground"
                android:layout_alignLeft="@id/Bforeground"
                android:layout_alignRight="@id/Bforeground"
                android:layout_alignTop="@+id/Bforeground"
                android:onClick="clickedMe"
                android:gravity="center" />
        </RelativeLayout>

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >

            <RelativeLayout
                android:id="@+id/foreground"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center" >

                <TextView
                    android:id="@+id/button_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:textSize="20dp"
                    android:text="Save" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_toLeftOf="@id/button_text"
                    android:paddingBottom="10dip"
                    android:paddingTop="10dip"
                    android:src="@drawable/save" />
            </RelativeLayout>
                        <Button
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_alignBottom="@id/foreground"
                android:layout_alignLeft="@id/foreground"
                android:layout_alignRight="@id/foreground"
                android:layout_alignTop="@+id/foreground"
                android:onClick="clickedMe"
                android:gravity="center" />
        </RelativeLayout>
    </LinearLayout>
    <ScrollView
        android:id="@+id/editRecordScrollView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/editRecordLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

        </LinearLayout>
    </ScrollView>
</LinearLayout>
4

1 回答 1

2

您必须将所有 UI 元素放置在单个父布局中。我建议您仍然可以使用 aLinearLayout作为顶层,但它应该是垂直的,如下所示:

android:orientation="vertical"

在父垂直 LinearLayout 中,您可以为顶部按钮和 a 放置水平 LinearLayout ScrollView。那应该这样做。

于 2013-03-22T03:18:21.097 回答