Reputation: 816
My Scrollview is not scrolling with a LinearLayout android
any idea why? if so please respond, I recently started on android so it might be really easy thing. But i searched and couldn't fix it. help would be gladly appreciated.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:nestedScrollingEnabled="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/textView"
android:layout_gravity="center_horizontal"
android:paddingBottom="80dp"/>
<android.support.v7.widget.CardView
android:layout_width="375dp"
android:layout_height="300dp"
android:layout_gravity="center_horizontal"
app:cardCornerRadius="0dp"
app:cardElevation="3dp"
app:cardBackgroundColor="#161616">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/image"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
Upvotes: 0
Views: 1113
Reputation: 2100
You cannot put a scrollable view (cardView) inside an another scrollable view (LinearLayout) because both scrolls are incompatible.
If you only have a TextView upper the CardView, I would remove the ScrollView and then the CardView will scroll normally. The layout structure should be:
<LinearLayout>
<TextView>
<Cardview>
...
</CardView>
</LinearLayout>
Hope it helps.
Upvotes: 0
Reputation: 1564
Looking at the layout, in portrait there is probably not enough content to even need the view to scroll. I plugged this into Android Studio and was only able to scroll when in landscape.
Also, as a general rule, the child of a ScrollView
(your LinearLayout
) should use wrap_content
instead of match_parent
.
If you want your ScrollView
to always at least fill the screen, you can use the android:fillViewPort="true"
attribute on your ScrollView
.
Upvotes: 1