XML 布局 - 滚动后按钮 n 或可见



我有一个XML布局如下。我有一个 TExt 视图,后跟许多复选框,然后是一个按钮。我已经将所有复选框包含在线性布局中,并为此设置了一个滚动视图。'向下滚动后我无法查看我的按钮,我该怎么办?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView />
    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:orientation="vertical" >
        <LinearLayout>
            <CheckBox />
            <CheckBox />
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox />
            <CheckBox/>
            <CheckBox />
        </LinearLayout>
    </ScrollView>
    <Button
    </Button>
</LinearLayout>

滚动视图有条件滚动视图应该只有一个子视图子视图可能包含可能子子视图

如果要显示按钮,请使用"查看"概念

    <LinearLayout
        <TextView
    <ScrollView   
    <LinearLayout
      <CheckBox
        <CheckBox
        <CheckBox
        <CheckBox
        .

        <CheckBox
    LinearLayout>
    ScrollView>
        <Button
 android:layout_weight="1"
    LinearLayout >

你必须使用Relativelayout或FrameLayout以获得更好的解决方案。这是使用相对布局的代码

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <Button
            android:id="@+id/relative_button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
android:text="hello one"
             >
        </Button>
        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@id/relative_button"
             >
         <LinearLayout>
                <CheckBox />
                <CheckBox />
                <CheckBox/>
                <CheckBox/>
                <CheckBox/>
                <CheckBox/>
                <CheckBox/>
                <CheckBox/>
                <CheckBox />
                <CheckBox/>
                <CheckBox />
            </LinearLayout>
        </ScrollView>
    </RelativeLayout>

尝试以下代码。您需要将按钮与底部对齐,并将包含复选框的线性布局对齐在按钮顶部。我已经尝试了这段代码,它对我有用。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="ABC" />
    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:layout_above="@+id/button"
        android:orientation="vertical" >
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </ScrollView>
    <Button
        android:id="@+id/button"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

最新更新