【问题标题】:ScrollView XML View At BottomScrollView XML 视图在底部
【发布时间】:2019-08-06 14:55:38
【问题描述】:

我试图将“继续”按钮放在底部,但它与底部不对齐。当我使用 ScrollView 时出现此问题,下面是 XML 和图像。我尝试了所有可能的方法,在 XML 中使用 ScrollView 将继续按钮置于底部。 如果我不包括 scrollView 布局是根据我需要的

screenshot

<?xml version="1.0" encoding="utf-8"?>
   <ScrollView android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/backgroundColor"
    xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout 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"
    android:orientation="vertical"
    android:background="@color/backgroundColor">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="USER AGREEMENT"
        android:textColor="@android:color/white"
        android:gravity="center"
        android:id="@+id/userAgereement"
        android:layout_marginTop="20dp"
        android:textSize="@dimen/textSize"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Beijing Pinnacle Global &amp; Alex Edu\n(BPGE &amp; Alex Edu)"
        android:textColor="@android:color/white"
        android:gravity="center"    
        android:layout_marginEnd="5dp"
        android:layout_marginStart="5dp"
        android:id="@+id/belowHeadingText"
        android:layout_marginTop="20dp"
        android:textSize="@dimen/endSize"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Today's Date : 25th of August, 2019"
        android:textColor="@android:color/white"
        android:gravity="center"
        android:layout_marginTop="20dp"
        android:id="@+id/date"
        android:textSize="@dimen/endSize"/>

    <View
        android:layout_width="270dp"
        android:layout_gravity="center"
        android:layout_marginTop="4dp"
        android:background="@android:color/white"
        android:layout_height="1dp">

    </View>    

    <ImageView
        android:layout_marginTop="20dp"
        android:layout_width="171dp"
        android:layout_height="239dp"
        android:layout_gravity="center"
        android:clickable="true"
        android:foreground="?attr/selectableItemBackgroundBorderless"
        android:src="@drawable/useragreemnet"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="You Are Going To Sign The User Agreement\nKindly, Provide Us Your Details"
        android:textColor="@android:color/white"
        android:gravity="center"
        android:id="@+id/belowImageText"
        android:layout_marginTop="20dp"
        android:textSize="@dimen/endSize"/>    

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        android:layout_gravity="center"
        android:layout_height="match_parent">  

        <android.support.v7.widget.CardView
            android:layout_width="230dp"    
            app:cardElevation="@dimen/elevation"
            app:cardCornerRadius="@dimen/cornerRadiusForButtons"
            app:cardBackgroundColor="@color/functionalityColor"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="20dp"
            android:layout_height="@dimen/buttonHeight">

            <Button    
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="@dimen/buttonHeight"
                android:clickable="true"
                android:foreground="?attr/selectableItemBackgroundBorderless"
                android:id="@+id/proceed"
                android:text="PROCEED"
                android:onClick="onClick"
                android:textSize="@dimen/buttonTextSize"
                android:textColor="@android:color/white"
                android:background="@android:color/transparent" 
                android:layout_marginBottom="20dp"/>
         </android.support.v7.widget.CardView>        

    </RelativeLayout>

</LinearLayout>        

</ScrollView>

【问题讨论】:

  • 嗨 saad ,看看我下面的答案会解决你的问题

标签: android xml android-layout


【解决方案1】:

在你的布局文件中使用这个 xml 代码,它将保持继续按钮向下

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/backgroundColor">

        <LinearLayout 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"
            android:background="@color/backgroundColor"
            android:orientation="vertical">


            <TextView
                android:id="@+id/userAgereement"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="USER AGREEMENT"
                android:textColor="@android:color/white"
                android:textSize="@dimen/textSize" />

            <TextView
                android:id="@+id/belowHeadingText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="5dp"
                android:layout_marginTop="20dp"

                android:layout_marginEnd="5dp"
                android:gravity="center"
                android:text="Beijing Pinnacle Global &amp; Alex Edu\n(BPGE &amp; Alex Edu)"
                android:textColor="@android:color/white"
                android:textSize="@dimen/endSize" />


            <TextView
                android:id="@+id/date"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="Today's Date : 25th of August, 2019"
                android:textColor="@android:color/white"
                android:textSize="@dimen/endSize" />

            <View
                android:layout_width="270dp"
                android:layout_height="1dp"
                android:layout_gravity="center"
                android:layout_marginTop="4dp"
                android:background="@android:color/white">

            </View>


            <ImageView
                android:layout_width="171dp"
                android:layout_height="239dp"
                android:layout_gravity="center"
                android:layout_marginTop="20dp"
                android:clickable="true"
                android:foreground="?attr/selectableItemBackgroundBorderless"
                android:src="@drawable/useragreemnet"

                />

            <TextView
                android:id="@+id/belowImageText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="You Are Going To Sign The User Agreement\nKindly, Provide Us Your Details"
                android:textColor="@android:color/white"
                android:textSize="@dimen/endSize" />


        </LinearLayout>


    </ScrollView>

    <android.support.design.widget.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="20dp">

            <android.support.v7.widget.CardView
                app:cardBackgroundColor="@color/functionalityColor"

                app:cardCornerRadius="@dimen/cornerRadiusForButtons"
                app:cardElevation="@dimen/elevation"
                android:layout_width="230dp"
                android:layout_height="@dimen/buttonHeight"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"

                android:layout_marginBottom="20dp">

                <Button

                    android:id="@+id/proceed"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/buttonHeight"
                    android:layout_marginBottom="20dp"
                    android:background="@android:color/transparent"
                    android:clickable="true"
                    android:foreground="?attr/selectableItemBackgroundBorderless"
                    android:gravity="center"
                    android:onClick="onClick"
                    android:text="PROCEED"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/buttonTextSize" />

            </android.support.v7.widget.CardView>


        </RelativeLayout>

    </android.support.design.widget.BottomNavigationView>
</RelativeLayout>

【讨论】:

  • 感谢您抽出宝贵时间@Thunder。此代码使继续按钮不可见。我需要在整个布局的末尾制作继续按钮。我插入 ScrollView 的原因是,如果 android 设备的屏幕尺寸相对于布局内容较小,因此它们可以向下滚动。如果用户有一个大屏幕,那么滚动视图当然不会滚动,但我需要的是在布局底部带来继续按钮
  • 希望对你有所帮助:)
猜你喜欢
  • 2016-04-26
  • 2013-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-23
  • 1970-01-01
相关资源
最近更新 更多