我浏览过很多SO和其他论坛,但是当我的LinearLayout
没有滚动时,当它的孩子碰巧超过可用的屏幕空间时,我无法得到答案。
所提供的答案都没有奏效。有趣的是,我还有其他几个活动,(我认为)主要是相同的布局,从来没有滚动那些问题。
这是我的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:background="@android:color/holo_blue_bright"
android:backgroundTint="@android:color/holo_blue_light"
android:backgroundTintMode="src_over"
android:fitsSystemWindows="true"
app:statusBarBackground="@color/LightGreen1"
tools:context="com.sbm.bc.smartbooksmobile.ActivityTeacherHwkAddTask">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/side_nav_bar"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/holo_blue_dark"
android:elevation="0dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:background="@android:color/holo_blue_bright"
android:clickable="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="10dp"
android:orientation="horizontal"
android:paddingTop="7dip">
<TableRow
android:id="@+id/beforeSearchTabRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="10dp">
<EditText
android:id="@+id/SeekTopicBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/actionModeSplitBackground"
android:clickable="true"
android:elevation="15dp"
android:focusable="true"
android:inputType="text"
android:onClick="onSeekTopicBoxClick"
android:selectAllOnFocus="true"
android:text="@string/seekTopic"
android:textIsSelectable="true"
android:textSize="18sp" />
<ImageButton
android:id="@+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-9dp"
android:elevation="17dp"
android:onClick="onSearchButtonClick"
app:srcCompat="@android:drawable/ic_search_category_default" />
</TableRow>
</LinearLayout>
<CheckBox
android:id="@+id/allTopics"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_marginTop="-35dp"
android:text="@string/everything"
android:textAlignment="viewStart"
android:onClick="onAllTopicsClick"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/SharpGreen1"
android:elevation="7dp"
android:orientation="horizontal">
<TextView
android:id="@+id/GradeColumnLabel"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="5"
android:ems="10"
android:text="@string/year_of_study"
android:textStyle="bold" />
<TextView
android:id="@+id/TopicColumnLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:gravity="start"
android:text="@string/topic"
android:textAlignment="center"
android:textStyle="bold" />
<TextView
android:id="@+id/HomeworkColumnLabel"
android:layout_width="33dp"
android:layout_height="wrap_content"
android:elevation="1dp"
android:ems="10"
android:gravity="center"
android:text="@string/homework"
android:textStyle="bold" />
<TextView
android:id="@+id/TestColumnLabel"
android:layout_width="33dp"
android:layout_height="wrap_content"
android:elevation="1dp"
android:ems="10"
android:gravity="center"
android:text="@string/test_short"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/ListOfTopics"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_bright"
android:elevation="7dp"
android:isScrollContainer="true"
android:orientation="vertical"
android:overScrollMode="ifContentScrolls" />
<TextView
android:id="@+id/NoTasksMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@android:color/holo_green_dark"
android:textAlignment="center"
android:visibility="visible"
tools:text="Nenašli sa žiadne úlohy .." />
</LinearLayout>
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<LinearLayout
android:id="@+id/fullscreen_content_controls"
style="?metaButtonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/black_overlay"
android:elevation="7dp"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button
android:id="@+id/addHomeworkBtn"
style="?metaButtonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:alpha="50"
android:elevation="3dp"
android:onClick="onSendButtonClick"
android:text="@string/next" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
重要的部分/对象是:
ListOfTopics&lt;&lt; , 我扩展了另一个项目:带孩子的LinearLayouts。
这是我展开/注入的内容:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/schoolGrade"
android:layout_width="33dp"
android:layout_height="wrap_content"
android:layout_weight="0.14"
android:text="Rocnik" />
<TextView
android:id="@+id/TopicName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Tema" />
<CheckBox
android:id="@+id/SelectTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foregroundTint="@color/SharpGreen1"
android:shadowColor="@android:color/holo_green_dark"
android:textColor="@color/colorPrimary"
android:textColorLink="@color/SharpGreen1" />
<CheckBox
android:id="@+id/SelectHwk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:shadowColor="@color/SharpGreen1"
android:textColor="@android:color/holo_blue_bright"
android:textColorLink="@android:color/holo_green_dark" />
</LinearLayout>
是的,我试图将名为&#34; ListOfTopics&#34;的顶级LinearLayout
放入容器变成ScrollView
,但没有帮助。而LinearLayout
本身就具有内在的能力,可以根据需要进行滚动。
我花了几个小时的时间来解决这个问题。有谁可以指出我做错了什么,拜托?
答案 0 :(得分:0)
如果要在scrollview中添加listview,可以尝试下面的代码
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.paolorotolo.expandableheightlistview.ExpandableHeightListView
android:id="@+id/expandable_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
</com.github.paolorotolo.expandableheightlistview.ExpandableHeightListView></ScrollView>
这对我有用。 对于这个listview github链接: https://github.com/paolorotolo/ExpandableHeightListView
答案 1 :(得分:0)
信不信由你,修复它的“神奇”就是改变我拥有的顶级CoordinatorLayout,换取别的东西。我尝试了RelativeLayout,它在我已有的其他活动中滚动得很好。
CoordinatorLayout
实现NestedScrollingParent2接口,它假设处理嵌套容器的滚动事件和委托,正如我所知道的那样。
有趣的是,即使使用CoordinatorLayout
,我也可以捕获嵌套视图上的所有触摸/滚动事件并手动处理它们(当然这不是我喜欢的)。