【问题标题】:How to set button at bottom if scroll enabled?如果启用滚动,如何在底部设置按钮?
【发布时间】:2017-10-13 07:30:27
【问题描述】:

我正在 android 中进行 Design。要求是当我在 scroll layout 中有超过 10 个字段 时,按钮应在下方对齐到末尾scroll view 如果我在布局中只有两个字段,它应该在屏幕底部静态对齐。现在我面临的问题是,如果我的字段少于 3 个,我的 Textview 按钮会出现在顶部(如果有)没有滚动并且它没有在屏幕底部对齐。我在此处附加我的 xml 请告诉我一些建议

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/signupRootLay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="?android:attr/actionBarSize">

<ImageView
    android:id="@+id/backgroundImage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop"
    android:src="@drawable/background" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#b3000000">

    <LinearLayout
        android:id="@+id/pageCountParentLay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/firstpageTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/circle_bg_with_low_contrast_color"
            android:gravity="center"
            android:text="@string/page_1"
            android:textColor="@color/high_contrast_color"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/secondPageTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/circle_bg_with_low_contrast_color"
            android:gravity="center"
            android:text="@string/page_2"
            android:textColor="@color/high_contrast_color"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/thirdPageTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/circle_bg_with_low_contrast_color"
            android:gravity="center"
            android:text="@string/page_3"
            android:textColor="@color/high_contrast_color"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/fourthPageTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/circle_bg_with_low_contrast_color"
            android:gravity="center"
            android:text="@string/page_4"
            android:textColor="@color/high_contrast_color"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/titleParentLay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/pageCountParentLay"
        android:orientation="horizontal">

        <View
            android:id="@+id/leftLine"
            android:layout_width="wrap_content"
            android:layout_height="1dp"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@color/secondary_color" />

        <TextView
            android:id="@+id/pageTitleTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/page_title_1"
            android:textColor="@color/secondary_color"
            android:textSize="18sp" />

        <View
            android:id="@+id/rightLine"
            android:layout_width="wrap_content"
            android:layout_height="1dp"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@color/secondary_color" />

    </LinearLayout>

    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        android:layout_below="@+id/titleParentLay">

        <LinearLayout
            android:id="@+id/parentLay"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <include layout="@layout/si_fields" />

            <include layout="@layout/si_exi_card_layout" />

            <include layout="@layout/password_layout" />
            <TextView
                android:id="@+id/nextTextView"
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:layout_alignParentBottom="true"
                android:background="@drawable/button_low_contrast_color_bg"
                android:gravity="center"
                android:text="@string/next_label"
                android:textColor="@color/high_contrast_color"
                android:textSize="18sp" />
        </LinearLayout>

    </ScrollView>




</RelativeLayout>

【问题讨论】:

  • 尝试用线性布局包裹滚动视图,并在滚动视图之后放置你的按钮,我想你可以实现你想要的。如果您希望您的按钮在 屏幕 底部静态可见,请尝试在相对布局中使用相同
  • 谢谢你我会试试@BerkayTutal
  • 它不起作用

标签: android xml material-design


【解决方案1】:

试试这个..在ScrollView中添加以下行

<ScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         android:fillViewport="true"/>

【讨论】:

  • 如果我应用了这个 fillviewport 并且 textview 按钮不在滚动视图内,最后两个包含布局就消失了
【解决方案2】:

只需将按钮放在滚动视图之外即可。 像这样的例子:

<ScrollView>
  <RelativeLayout>
  </RelativeLayout>
</ScrollView>
<Button />

【讨论】:

  • 如果字段多,我只需要滚动内的按钮,如果字段少,我只需要滚动外的按钮,并且我的所有字段都是动态的
猜你喜欢
  • 1970-01-01
  • 2018-05-04
  • 2020-11-11
  • 1970-01-01
  • 2020-09-25
  • 2019-10-05
  • 2021-01-31
  • 2015-09-22
  • 2018-07-29
相关资源
最近更新 更多