需要更有经验的开发人员的帮助。我在 android 中使用滚动的 Fragment 模板有问题。您不能以横向屏幕格式将屏幕滚动到最后。位于最底部的部分信息不显示。问题似乎是片段占用的空间超过了它可以在屏幕上显示的空间。我不明白我哪里出错了。请告诉我。
fragment_main.xml 标记
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
android:layout_height="wrap_content"
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:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainFragment">
<TextView
android:id="@+id/text_view_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:textSize="36sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text_view_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/weather_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view_location" />
<ImageView
android:id="@+id/weather_icon"
android:layout_width="240dp"
android:layout_height="240dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:adjustViewBounds="true"
android:contentDescription="@string/weatherIcon"
android:scaleType="fitStart"
app:layout_constraintBottom_toTopOf="@+id/temperature_view_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view_date" />
<TextView
android:id="@+id/temperature_view_text"
style="@style/Widget.AppCompat.TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="@string/temp_temperature"
android:textSize="48sp"
app:layout_constraintBottom_toTopOf="@+id/text_view_description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/weather_icon" />
<TextView
android:id="@+id/text_view_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:textSize="36sp"
app:layout_constraintBottom_toTopOf="@+id/tableRow"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/temperature_view_text" />
<TableRow
android:id="@+id/tableRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view_description">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/feels_like"
android:src="@drawable/ic_scarf" />
<TextView
android:id="@+id/text_view_feels_like"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="start"
android:textSize="24sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/myWind"
android:src="@drawable/ic_wind" />
<TextView
android:id="@+id/text_view_wind_speed"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="start"
android:textSize="24sp" />
</TableRow>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
嵌入此 Fragment 的主要活动的横向布局标记。
<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="wrap_content"
android:orientation="horizontal">
<include
android:id="@+id/include"
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/include">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/frag_cont_view_second"
android:name="ru.skillsnet.falchio.SecondFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
tools:layout="@layout/fragment_second" />
<androidx.fragment.app.FragmentContainerView
android:id="@+id/frag_cont_view_main"
android:name="ru.skillsnet.falchio.MainFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:layout="@layout/fragment_main" />
</TableRow>
</androidx.constraintlayout.widget.ConstraintLayout>
尝试
取而代之
这是唯一想到的