在我的代码中,我有3个LinearLayouts,我想让中间的一个可滚动,以便能够看到整个信息。
目前我的代码如下:
patient_home_page.xml
<LinearLayout 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:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/profileBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageViewPatientPicture"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="0"
android:scaleType="fitXY"
app:srcCompat="@drawable/profile_pic" />
<TextView
android:id="@+id/textViewPatientName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:fontFamily="sans-serif"
android:paddingLeft="20dp"
android:text="Anakin Skywalker" />
</LinearLayout>
<ScrollView
android:id="@+id/infoBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/profileBlock"
android:layout_above="@id/graphInfoBlock"
android:layout_marginLeft="10dp"
android:orientation="vertical"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textViewDOB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Date of Birth: 26/08/1963" />
<TextView
android:id="@+id/textViewGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="5dp"
android:text="Gender: Male" />
<TextView
android:id="@+id/textViewMedication"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="5dp"
android:text="Current Medication: - " />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingTop="5dp">
<TextView
android:id="@+id/textViewObservation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="Observations:" />
<TextView
android:id="@+id/textViewObservatonsInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer mollis nulla eu scelerisque ultricies. Etiam varius iaculis purus, et ullamcorper lectus tincidunt et. Nullam vel felis eu dolor condimentum dignissim. Vestibulum in tristique nulla. Mauris elit nibh, ullamcorper in imperdiet sed, luctus vitae nibh. Aliquam nisi nisi, mattis vitae cursus id, dignissim sollicitudin risus. Nam sed egestas mauris, sed scelerisque quam. Morbi sapien turpis, vestibulum at lacus vel, lacinia vehicula elit. Maecenas et lobortis felis. Vivamus elementum ut tortor efficitur iaculis. Vestibulum vestibulum dolor ut urna facilisis eleifend. Nulla gravida mattis eros sit amet molestie. Cras pellentesque sodales tortor, id efficitur neque ultrices at. Pellentesque lacus quam, euismod a dui et, ullamcorper luctus magna. Mauris semper sem vel neque hendrerit, hendrerit elementum nibh sodales." />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/graphInfoBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<com.jjoe64.graphview.GraphView
android:id="@+id/graphPressure"
android:layout_width="275dp"
android:layout_height="275dp" />
<ListView
android:id="@+id/listViewGraphValues"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
这给了我一个关于ScrollView的layout_above部分的错误,该部分说明了以下内容:
“错误:(47,35)找不到与给定名称匹配的资源(在'layout_above'处,值为'@id / graphInfoBlock')。”
这很奇怪,因为graphInfoBlock在下面定义。我尝试过没有layout_above设置,但它似乎没有用。
Here's a link to what it looks like without the layout_above setting
有什么建议吗?
答案 0 :(得分:0)
设置根布局RelativeLayout以使用layout_above或layout_below,并使用RelativeLayout属性调整视图或布局的位置。据我所知,你不能在LinearLayout中使用layout_above或类似的属性。
答案 1 :(得分:0)
我只对代码进行了一些小改动,只需粘贴并尝试
即可<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:id="@+id/profileBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageViewPatientPicture"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="0"
android:scaleType="fitXY"
app:srcCompat="@drawable/profile_pic" />
<TextView
android:id="@+id/textViewPatientName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:fontFamily="sans-serif"
android:paddingLeft="20dp"
android:text="Anakin Skywalker" />
</LinearLayout>
<ScrollView
android:id="@+id/infoBlock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/graphInfoBlock"
android:layout_below="@id/profileBlock"
android:layout_marginLeft="10dp"
android:fillViewport="true"
android:orientation="vertical"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textViewDOB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Date of Birth: 26/08/1963" />
<TextView
android:id="@+id/textViewGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="5dp"
android:text="Gender: Male" />
<TextView
android:id="@+id/textViewMedication"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="5dp"
android:text="Current Medication: - " />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingTop="5dp">
<TextView
android:id="@+id/textViewObservation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="Observations:" />
<TextView
android:id="@+id/textViewObservatonsInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer mollis nulla eu scelerisque ultricies. Etiam varius iaculis purus, et ullamcorper lectus tincidunt et. Nullam vel felis eu dolor condimentum dignissim. Vestibulum in tristique nulla. Mauris elit nibh, ullamcorper in imperdiet sed, luctus vitae nibh. Aliquam nisi nisi, mattis vitae cursus id, dignissim sollicitudin risus. Nam sed egestas mauris, sed scelerisque quam. Morbi sapien turpis, vestibulum at lacus vel, lacinia vehicula elit. Maecenas et lobortis felis. Vivamus elementum ut tortor efficitur iaculis. Vestibulum vestibulum dolor ut urna facilisis eleifend. Nulla gravida mattis eros sit amet molestie. Cras pellentesque sodales tortor, id efficitur neque ultrices at. Pellentesque lacus quam, euismod a dui et, ullamcorper luctus magna. Mauris semper sem vel neque hendrerit, hendrerit elementum nibh sodales." />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/graphInfoBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<com.jjoe64.graphview.GraphView
android:id="@+id/graphPressure"
android:layout_width="275dp"
android:layout_height="275dp" />
<ListView
android:id="@+id/listViewGraphValues"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
答案 2 :(得分:0)
将以下内容替换为:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/profileBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageViewPatientPicture"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="0"
android:scaleType="fitXY"
app:srcCompat="@drawable/profile_pic" />
<TextView
android:id="@+id/textViewPatientName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:fontFamily="sans-serif"
android:paddingLeft="20dp"
android:text="Anakin Skywalker" />
</LinearLayout>
<ScrollView
android:id="@+id/infoBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/graphInfoBlock"
android:layout_below="@+id/profileBlock"
android:layout_marginLeft="10dp"
android:fillViewport="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textViewDOB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Date of Birth: 26/08/1963" />
<TextView
android:id="@+id/textViewGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="5dp"
android:text="Gender: Male" />
<TextView
android:id="@+id/textViewMedication"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="5dp"
android:text="Current Medication: - " />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingTop="5dp">
<TextView
android:id="@+id/textViewObservation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="Observations:" />
<TextView
android:id="@+id/textViewObservatonsInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer mollis nulla eu scelerisque ultricies. Etiam varius iaculis purus, et ullamcorper lectus tincidunt et. Nullam vel felis eu dolor condimentum dignissim. Vestibulum in tristique nulla. Mauris elit nibh, ullamcorper in imperdiet sed, luctus vitae nibh. Aliquam nisi nisi, mattis vitae cursus id, dignissim sollicitudin risus. Nam sed egestas mauris, sed scelerisque quam. Morbi sapien turpis, vestibulum at lacus vel, lacinia vehicula elit. Maecenas et lobortis felis. Vivamus elementum ut tortor efficitur iaculis. Vestibulum vestibulum dolor ut urna facilisis eleifend. Nulla gravida mattis eros sit amet molestie. Cras pellentesque sodales tortor, id efficitur neque ultrices at. Pellentesque lacus quam, euismod a dui et, ullamcorper luctus magna. Mauris semper sem vel neque hendrerit, hendrerit elementum nibh sodales." />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/graphInfoBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<com.jjoe64.graphview.GraphView
android:id="@+id/graphPressure"
android:layout_width="275dp"
android:layout_height="275dp" />
<ListView
android:id="@+id/listViewGraphValues"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
答案 3 :(得分:0)
试试这个......它会起作用..
<RelativeLayout 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:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/profileBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageViewPatientPicture"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="0"
android:scaleType="fitXY"
app:srcCompat="@drawable/profile_pic3" />
<TextView
android:id="@+id/textViewPatientName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:fontFamily="sans-serif"
android:paddingLeft="20dp"
android:text="Anakin Skywalker" />
</LinearLayout>
<ScrollView
android:id="@+id/infoBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/profileBlock"
android:layout_above="@id/graphInfoBlock"
android:layout_marginLeft="10dp"
android:orientation="vertical"
android:fillViewport="true">
<!-- -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textViewDOB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Date of Birth: 26/08/1963" />
<TextView
android:id="@+id/textViewGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="5dp"
android:text="Gender: Male" />
<TextView
android:id="@+id/textViewMedication"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="5dp"
android:text="Current Medication: - " />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingTop="5dp">
<TextView
android:id="@+id/textViewObservation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="Observations:" />
<TextView
android:id="@+id/textViewObservatonsInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer mollis nulla eu scelerisque ultricies. Etiam varius iaculis purus, et ullamcorper lectus tincidunt et. Nullam vel felis eu dolor condimentum dignissim. Vestibulum in tristique nulla. Mauris elit nibh, ullamcorper in imperdiet sed, luctus vitae nibh. Aliquam nisi nisi, mattis vitae cursus id, dignissim sollicitudin risus. Nam sed egestas mauris, sed scelerisque quam. Morbi sapien turpis, vestibulum at lacus vel, lacinia vehicula elit. Maecenas et lobortis felis. Vivamus elementum ut tortor efficitur iaculis. Vestibulum vestibulum dolor ut urna facilisis eleifend. Nulla gravida mattis eros sit amet molestie. Cras pellentesque sodales tortor, id efficitur neque ultrices at. Pellentesque lacus quam, euismod a dui et, ullamcorper luctus magna. Mauris semper sem vel neque hendrerit, hendrerit elementum nibh sodales." />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/graphInfoBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<com.jjoe64.graphview.GraphView
android:id="@+id/graphPressure"
android:layout_width="275dp"
android:layout_height="275dp" />
<ListView
android:id="@+id/listViewGraphValues"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</RelativeLayout>