Making LinearLayout Scrollable

2019-08-30 17:17发布

问题:

I am trying to make a linear layout scrollable by using a scrollView so that the images put into the imageViews don't push the other views and functions off of the screen like this:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

<TextView
    android:id="@+id/personalizetextView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/customize" 
    android:textSize="30sp"
    android:gravity="center"
    android:layout_marginTop="20dip"/>

<TextView 
    android:id="@+id/personalizetextviewChangeBackground"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/customizebackground"
    android:gravity="center" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"  
    android:maxWidth="100dp"  
    android:maxHeight="100dp"  
    android:scaleType="fitCenter"  
    android:contentDescription="@string/descForBackground"

    />

<Button
    android:id="@+id/btnChangeImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/change_background" />

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/set_background" 
    android:id="@+id/btnSetBackground" />

 <TextView 
    android:id="@+id/personalizetextviewChangeIcon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/change_icon"
    android:gravity="center" />

 <ImageView
    android:id="@+id/imageView2Icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"  
    android:maxWidth="100dp"  
    android:maxHeight="100dp"  
    android:scaleType="fitCenter"
    android:contentDescription="@string/descForIcon"
     />

<Button
    android:id="@+id/btnChangeImageForIcon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/change_icon" />

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/set_icon" 
    android:id="@+id/btnSetIcon" />

  <Button
        android:id="@+id/btnLinkToFeedback"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dip"
        android:background="@null"
        android:text="@string/Send_Feedback"
        android:textColor="#21dbd4"
        android:textStyle="bold" />

        </LinearLayout>
</ScrollView>

But it just makes it so that my first textView shows up and nothing else. What can I do to fix this?

回答1:

Put

android:orientation="vertical"

in LinearLayout and not in ScrollView ;)

The default orientation for LinearLayout is horizontal and your TextView probably spans across multiple lines.