我正在构建一个具有scrollview的简单布局,并使用约束布局
我接近拥有我需要的东西,我只需要调整2个视图,一个描述标题,并在其底部分别说明。
问题是,底部的元素没有调整我尝试将内容包装在高度上,因为元素描述可以增长,但是当我这样做时,视图只是消失并且上面的任何元素都滚动到,
对此有何帮助?
这是我的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:fillViewport="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="@+id/my_toolbar"
layout="@layout/custom_toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="@+id/SpecieName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="22dp"
android:text="adas "
android:textColor="@color/nephritis"
android:textSize="14dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="@+id/textView8"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/googleMapsText" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="@+id/GenreName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="8dp"
android:layout_marginStart="12dp"
android:onClick="genrePressed"
android:text="asdas "
android:textColor="@color/nephritis"
android:textSize="14dp"
app:layout_constraintBottom_toBottomOf="@+id/textView7"
app:layout_constraintHorizontal_bias="0.004"
app:layout_constraintLeft_toRightOf="@+id/textView7"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="@+id/FamilyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="11dp"
android:layout_marginRight="8dp"
android:layout_marginStart="11dp"
android:layout_marginTop="38dp"
android:onClick="familyPressed"
android:text="asdaswwww"
android:textColor="@color/nephritis"
android:textSize="14dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="@+id/Family"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/GenreName"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="@+id/textView8"
android:layout_width="65dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:text="Espécie"
android:textSize="14dp"
app:layout_constraintBaseline_toBaselineOf="@+id/SpecieName"
app:layout_constraintLeft_toLeftOf="parent"
tools:layout_constraintBaseline_creator="1"
tools:layout_constraintLeft_creator="1" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="@+id/textView7"
android:layout_width="58dp"
android:layout_height="0dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="36dp"
android:text="Género"
android:textSize="14dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView8"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="@+id/Family"
android:layout_width="71dp"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:text="Familia"
android:textSize="14dp"
app:layout_constraintLeft_toLeftOf="@+id/textView7"
app:layout_constraintTop_toBottomOf="@+id/textView7"
app:layout_heightPercent="5%"
app:layout_marginLeftPercent="5%"
app:layout_marginTopPercent="105%"
app:layout_widthPercent="25%"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
<ImageView
android:id="@+id/plantImage"
android:layout_width="0dp"
android:layout_height="275dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/my_toolbar"
app:srcCompat="@drawable/color_cursor_white" />
<android.support.v7.widget.RecyclerView
android:id="@+id/gallery"
android:layout_width="0dp"
android:layout_height="77dp"
android:layout_marginTop="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/plantImage"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="@+id/googleMapsText"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="8dp"
android:layout_marginStart="20dp"
android:layout_marginTop="19dp"
android:text="Ver no mapa"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="@+id/imageView6"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/gallery"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<ImageView
android:id="@+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="11dp"
android:src="@drawable/ic_facebook_placeholder_for_locate_places_on_maps"
android:tint="#F90101"
app:layout_constraintLeft_toLeftOf="@+id/gallery"
app:layout_constraintTop_toBottomOf="@+id/gallery"
tools:layout_conversion_absoluteHeight="0dp"
tools:layout_conversion_absoluteWidth="0dp"
tools:layout_conversion_absoluteX="360dp"
tools:layout_conversion_absoluteY="0dp" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="@+id/specieDescription"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="8dp"
android:text="asdfasd "
android:textSize="14dp"
app:layout_constraintLeft_toLeftOf="@+id/descricaoTit"
app:layout_constraintTop_toBottomOf="@+id/descricaoTit"
app:layout_marginLeftPercent="5%"
app:layout_marginTopPercent="120%"
app:layout_widthPercent="90%"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="@+id/descricaoTit"
android:layout_width="71dp"
android:layout_height="wrap_content"
android:text="Descrição"
android:textSize="14dp"
android:layout_marginLeft="-16dp"
app:layout_constraintLeft_toLeftOf="@+id/Family"
android:layout_marginTop="25dp"
app:layout_constraintTop_toBottomOf="@+id/Family"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
重要部分:
标题:
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="@+id/descricaoTit"
android:layout_width="71dp"
android:layout_height="wrap_content"
android:text="Descrição"
android:textSize="14dp"
android:layout_marginLeft="-16dp"
app:layout_constraintLeft_toLeftOf="@+id/Family"
android:layout_marginTop="25dp"
app:layout_constraintTop_toBottomOf="@+id/Family"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0" />
说明:
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="@+id/specieDescription"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="8dp"
android:text="asdfasd "
android:textSize="14dp"
app:layout_constraintLeft_toLeftOf="@+id/descricaoTit"
app:layout_constraintTop_toBottomOf="@+id/descricaoTit"
app:layout_marginLeftPercent="5%"
app:layout_marginTopPercent="120%"
app:layout_widthPercent="90%"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent" />
非常感谢:)。
答案 0 :(得分:0)
当您有多个视图或小部件时,最好使用相对布局而不是约束。