更新的问题:我试图滚动但根本不滚动。检查图片:
OLD:
我的线性布局中还有5张卡片视图,但我只是粘贴了1.我不知道是什么导致了scrollview的问题。我已经尝试删除第一个线性布局,但没有工作。
XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_nearby_newest"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:background="#fafafa"
android:fitsSystemWindows="true"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:id="@+id/scrollView"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp"
android:layout_margin="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin fermentum vulputate finibus. Morbi venenatis blandit purus, sit amet ultricies elit laoreet imperdiet. Morbi suscipit diam non consequat faucibus. Aliquam erat volutpat. Mauris luctus, eros nec mollis dapibus, lorem nunc pharetra arcu, ut rhoncus erat erat sed mi. Morbi condimentum lacinia augue, nec malesuada ligula posuere suscipit. Sed vehicula ex cursus, tempor libero eu, finibus metus."
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp"
android:layout_margin="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin fermentum vulputate finibus. Morbi venenatis blandit purus, sit amet ultricies elit laoreet imperdiet. Morbi suscipit diam non consequat faucibus. Aliquam erat volutpat. Mauris luctus, eros nec mollis dapibus, lorem nunc pharetra arcu, ut rhoncus erat erat sed mi. Morbi condimentum lacinia augue, nec malesuada ligula posuere suscipit. Sed vehicula ex cursus, tempor libero eu, finibus metus."
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp"
android:layout_margin="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin fermentum vulputate finibus. Morbi venenatis blandit purus, sit amet ultricies elit laoreet imperdiet. Morbi suscipit diam non consequat faucibus. Aliquam erat volutpat. Mauris luctus, eros nec mollis dapibus, lorem nunc pharetra arcu, ut rhoncus erat erat sed mi. Morbi condimentum lacinia augue, nec malesuada ligula posuere suscipit. Sed vehicula ex cursus, tempor libero eu, finibus metus."
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp"
android:layout_margin="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin fermentum vulputate finibus. Morbi venenatis blandit purus, sit amet ultricies elit laoreet imperdiet. Morbi suscipit diam non consequat faucibus. Aliquam erat volutpat. Mauris luctus, eros nec mollis dapibus, lorem nunc pharetra arcu, ut rhoncus erat erat sed mi. Morbi condimentum lacinia augue, nec malesuada ligula posuere suscipit. Sed vehicula ex cursus, tempor libero eu, finibus metus."
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin fermentum vulputate finibus. Morbi venenatis blandit purus, sit amet ultricies elit laoreet imperdiet. Morbi suscipit diam non consequat faucibus. Aliquam erat volutpat. Mauris luctus, eros nec mollis dapibus, lorem nunc pharetra arcu, ut rhoncus erat erat sed mi. Morbi condimentum lacinia augue, nec malesuada ligula posuere suscipit. Sed vehicula ex cursus, tempor libero eu, finibus metus."
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</FrameLayout>
答案 0 :(得分:0)
滚动视图在其内容达到其父级大小
之前不会滚动了解一下这个例子看看
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frame"
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/app_bar_main">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_marginTop="30dp"
android:layout_height="wrap_content">
// now scroll is 200dp in height
<ScrollView
android:layout_width="match_parent"
android:layout_height="200dp">
// child of scroll
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="200dp">
//inner children have more height than scroll view height (total 600dp) which made scroll view to scroll
<LinearLayout
android:background="#000"
android:layout_width="match_parent"
android:layout_height="300dp"></LinearLayout>
<LinearLayout
android:background="#0F0"
android:layout_width="match_parent"
android:layout_height="300dp"></LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</FrameLayout>