我正在创建一个自定义对话框,其中包含大量元素的ScrollView。
问题是ScrollView将所有内容移动到顶部。好像它增加了保证金底部。因此,当ScrollView滑动到底部时,顶级内容被裁剪并且机器人内容具有太多可用空间。请看截图。
1)当滑到顶部时,裁剪内容。
2)当滑到底部时,内容有余量
它应该是这样的:
代码: dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/pop_margin_outer">
<View
android:id="@+id/view_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_rounded_rectangle"
android:layout_alignTop="@+id/ll_content"
android:layout_alignBottom="@id/ll_content"
android:layout_alignEnd="@id/ll_content"
android:layout_alignStart="@id/ll_content"
android:layout_alignLeft="@id/ll_content"
android:layout_alignRight="@id/ll_content"/>
<include layout="@layout/content_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/activity_vertical_margin"
android:layout_marginEnd="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_vertical_margin"
android:layout_marginStart="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_horizontal_margin_48"
android:layout_marginTop="@dimen/activity_horizontal_margin_48"
android:layout_centerInParent="true"/>
<ImageView
android:id="@+id/iv_dialog_close"
android:layout_width="@dimen/btn_x_size"
android:layout_height="@dimen/btn_x_size"
android:src="@drawable/ic_x"
android:layout_above="@id/view_bg"
android:layout_alignEnd="@id/view_bg"
android:layout_alignRight="@id/view_bg"
android:layout_marginTop="@dimen/item_padding_small"
android:layout_marginRight="@dimen/item_padding_small"
android:layout_marginEnd="@dimen/item_padding_small"
android:layout_marginBottom="@dimen/item_padding_small"
/>
代码: dialog_content.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:paddingBottom="@dimen/pop_space_vertical_24"
android:paddingLeft="@dimen/pop_space_vertical_24"
android:paddingRight="@dimen/pop_space_vertical_24"
android:paddingTop="@dimen/pop_space_vertical_36">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tv_headline"
style="@style/yellow_text_middle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="@dimen/pop_space_vertical_24"
android:text="@string/db_headline"
android:textSize="@dimen/middle_text_min" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
style="@style/yellow_text_small"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/db_content_1" />
<TextView
android:id="@+id/tv_app_name"
style="@style/yellow_text_small"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/app_name"
android:textSize="@dimen/middle_text_min" />
</LinearLayout>
<TextView
style="@style/yellow_text_small"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/pop_space_vertical_24"
android:gravity="center"
android:text="@string/db_content_2" />
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/small_logo"
android:layout_marginBottom="@dimen/pop_space_vertical_24"
android:src="@drawable/ic_logo" />
<TextView
style="@style/teal_text_small"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/pop_space_vertical_24"
android:gravity="center"
android:text="@string/db_content_3" />
<include layout="@layout/content_broker_input" />
<Button
android:id="@+id/btn_continue"
style="@style/btn_bg_yellow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/pop_space_vertical_24"
android:text="@string/db_btn_continue" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
为什么ScrollView有这种行为的想法?