【问题标题】:how to give space at the bottom of page if using scroll view如果使用滚动视图,如何在页面底部留出空间
【发布时间】:2020-09-25 13:45:01
【问题描述】:

这里我使用了滚动视图,我想在页面底部留出一个空间,这样只有条款和条件可以滚动,并且复选框和按钮不滚动它应该在页面底部,你能帮我吗? xml。我附上了一张图片,我想要这样的设计,底部的按钮不会移动Design Example herea

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Common.PolcyPage">

    <LinearLayout
        android:id="@+id/liner_layout_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="35dp"
                android:layout_marginLeft="35dp"
                android:layout_marginTop="60dp"
                android:fontFamily="@font/segoe_ui_bold"
                android:text="@string/terms_of_services"
                android:textColor="@color/colorTandC"
                android:textSize="25sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="35dp"
                android:layout_marginLeft="35dp"
                android:text="@string/updated_date_terms"
                android:textColor="@color/colorTandC_titles" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:layout_marginTop="38dp"
                android:background="@color/colorTandC_desc" />

        </LinearLayout>

        <ScrollView
            android:scrollbars="none"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="35dp"
                android:layout_marginLeft="35dp"
                android:layout_marginTop="35dp"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/segoe_ui_semibold"
                    android:text="@string/terms_one_title"
                    android:textColor="@color/colorTandC_titles"
                    android:textSize="14sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:layout_marginEnd="30dp"
                    android:layout_marginRight="30dp"
                    android:text="@string/terms_one_desc"
                    android:textColor="@color/colorTandC_desc"
                    android:textSize="13sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="30dp"
                    android:fontFamily="@font/segoe_ui_semibold"
                    android:text="@string/terms_two_title"
                    android:textColor="@color/colorTandC_titles"
                    android:textSize="14sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:layout_marginEnd="30dp"
                    android:layout_marginRight="30dp"
                    android:text="@string/terms_two_desc"
                    android:textColor="@color/colorTandC_desc"
                    android:textSize="13sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="25dp"
                    android:layout_marginLeft="25dp"
                    android:layout_marginEnd="30dp"
                    android:layout_marginRight="30dp"
                    android:text="@string/terms_two_desc_terms"
                    android:textColor="@color/colorTandC_desc"
                    android:textSize="13sp" />

            </LinearLayout>

        </ScrollView>

    </LinearLayout>

</RelativeLayout>

【问题讨论】:

    标签: android android-studio user-interface graphics android-xml


    【解决方案1】:

    尝试在屏幕底部甚至滚动视图下方添加按钮

    在 scrollView 或 Parent LinearLayout 中添加这个石灰

    <ScrollView>
       android:layout_above="@+id/bottom_panel"
    

    在你的 xml 的最底部添加这个

           </ScrollView>
    
        </LinearLayout>
    --------------- ADD HERE - Below Scroll View -------
        <LinearLayout
            android:id="@+id/bottom_panel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
    
            android:gravity="center|bottom"     OR    android:layout_alignParentBottom="true"
    
            android:orientation="horizontal">
    
            <Button 
                android:layout_width="0dip"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Decline"/>
    
            <Button 
                android:layout_width="0dip"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Accept"/>
        </LinearLayout>
    
    </RelativeLayout>
    

    让我知道它是否工作正常

    【讨论】:

    • 当 ''''android:layout_above="@+id/bottom_panel" 放置在父线性布局中时,这可以正常工作。谢谢
    • 很高兴知道它对您有用,您可以将答案标记为正确,无论哪个最适合您,也可以点赞:)
    【解决方案2】:

    如果我正确理解你的问题,你可以这样写:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    <LinearLayout
        android:id="@+id/bottom_parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="32dp"
            android:paddingRight="32dp"
            android:gravity="center"
            android:orientation="horizontal">
    
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:text="I agree with the Terms and Conditions"/>
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="32dp"
            android:paddingRight="32dp"
            android:gravity="center"
            android:orientation="horizontal">
    
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:text="I agree with the Privacy Policy"/>
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="32dp"
            android:paddingRight="32dp"
            android:paddingTop="16dp"
            android:paddingBottom="32dp"
            android:orientation="horizontal">
    
            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight=".5"
                android:layout_marginRight="32dp"
                android:text="decline"/>
    
            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight=".5"
                android:text="accept"/>
    
        </LinearLayout>
    
    </LinearLayout>
    
    <LinearLayout
        android:id="@+id/top_parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="32dp"
        android:paddingRight="32dp"
        android:paddingTop="16dp"
        android:paddingBottom="8dp"
        android:gravity="center_vertical"
        android:orientation="horizontal">
    
        <ImageView
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:src="@drawable/your_image"/>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:orientation="vertical">
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:text="Terms of service"/>
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Update date"/>
    
        </LinearLayout>
    
    </LinearLayout>
    
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/bottom_parent"
        android:layout_below="@id/top_parent">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <!-- ADD YOUR TEXTVIEWS HERE -->
    
        </LinearLayout>
    
    </ScrollView>
    

    使用 android:layout_above 和 android:layout_below 来定义您的 ScrollView 位置

    【讨论】:

      猜你喜欢
      • 2015-03-23
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      • 2016-07-10
      • 2016-06-17
      • 2021-01-11
      • 2013-01-19
      • 1970-01-01
      相关资源
      最近更新 更多