【发布时间】:2021-07-18 00:08:47
【问题描述】:
我正在开发一个应用程序,我需要在一个活动中使用 2 个片段。根据对第一个片段所做的选择,将显示第二个片段。问题是第二个片段没有向下滚动,在屏幕末尾被切断。
这里是包含“固定”和动态插入片段的活动的 XML (activity_inspection.xml)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".activities.InspectionActivity"
android:padding="@dimen/margins">
<fragment
android:id="@+id/chooseItemMemorial"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
class="com.xxxx.xxxxx.fragments.InspectionMemorial"/>
<FrameLayout
android:id="@+id/show_fragment_selected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/chooseItemMemorial"
android:layout_marginTop="@dimen/top_margins"/>
</androidx.constraintlayout.widget.ConstraintLayout>
这是我想动态插入到我的活动中的片段之一的 sn-p:(fragment_external_access.xml)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content"
android:scrollbars="vertical"
tools:context=".fragments.ExternalAccessFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
/** here goes the rest of the code**/
编辑:我想要实现的是通过<fragment> 标签添加的第一个片段保持固定在屏幕上,而通过代码动态添加的第二个片段能够在必要时滚动。
我尝试使用 ScrollView 和 NestedScrollView 没有成功。但这可能是一些愚蠢的错误,比如忘记添加标签。由于我是 android 编程新手,我们将不胜感激。
为了结束这个(因为它可能是相关的),这是我用来添加这个片段的 java 代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_external_access, container, false);
}
【问题讨论】:
标签: java android android-layout android-fragments android-constraintlayout