0

在我的应用程序中,我想提供在屏幕上滚动整个布局的功能。在这里,我还在 ScrollView 中包装了 Linearlayout,但它不提供滚动功能。以下是我的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/ScrollView01"
    >

<LinearLayout  
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:paddingTop="50dp"
  android:weightSum="1"
  android:layout_marginTop="67dp"
  >

    <ImageView 
        android:id="@+id/artistImageView"
        android:layout_width="fill_parent"
        android:layout_height="150dp"
        android:paddingTop="10dp"
        android:layout_marginTop="67dp"
        android:background="#000000"
    />

    <TextView
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:text="BIOGRAPHY"
        android:textColor="#eeeeee"
        android:background="#000000"
        android:id="@+id/txt1"
    />          
    <ImageView
        android:src="@drawable/separator_bio"
        android:scaleType="fitXY"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"            
        android:background="#000000"
        android:id="@+id/sep1"
    />                  
    <TextView  
        android:id="@+id/artistView" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"         
        android:textStyle="bold"
        android:textColor="#ffffff"              
        android:paddingLeft="10dp"
        android:paddingRight="5dp"        
        android:background="#000000"
    />
</LinearLayout>
</ScrollView>

请提出解决方案。谢谢。

4

3 回答 3

0

我建议将线性布局中的内容高度更改为 wrap_content

<LinearLayout  
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   android:paddingTop="50dp"
   android:weightSum="1"
   android:layout_marginTop="67dp"
   >

包装内容的原因是这样滚动视图将填满屏幕并且线性布局可以自由溢出。这个溢出就是你要滚动的内容

编辑:

在查看您的代码之后,您实际上并不需要该android:weightSum="1"行,因为您从不使用重量来定义任何孩子的身高。此外,当使用 wrap_content 时,父视图中永远不会有剩余空间,因此重量不会像您期望的那样工作:)

于 2012-11-26T19:16:55.743 回答
0

你上面的代码对我有用意味着滚动在你上面的代码中从我这边工作。

如果您这边此代码不起作用,请尝试此操作。

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"

  >
<ScrollView

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/ScrollView01"
    >

<LinearLayout  
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:paddingTop="50dp"
  android:weightSum="1"
  android:layout_marginTop="67dp"
  >

    <ImageView 
        android:id="@+id/artistImageView"
        android:layout_width="fill_parent"
        android:layout_height="150dp"
        android:paddingTop="10dp"
        android:layout_marginTop="67dp"
        android:background="#000000"
    />

    <TextView
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:text="BIOGRAPHY"
        android:textColor="#eeeeee"
        android:background="#000000"
        android:id="@+id/txt1"
    />          
    <ImageView
        android:src="@drawable/separator_bio"
        android:scaleType="fitXY"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"            
        android:background="#000000"
        android:id="@+id/sep1"
    />                  
    <TextView  
        android:id="@+id/artistView" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"         
        android:textStyle="bold"
        android:textColor="#ffffff"              
        android:paddingLeft="10dp"
        android:paddingRight="5dp"        
        android:background="#000000"
    />
</LinearLayout>
</ScrollView>
</LinearLayout>
于 2012-11-27T07:07:11.753 回答
0

这是适用于我的应用程序的最终代码。

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:id="@+id/ScrollView01"
    android:layout_marginTop="65dp"
    android:layout_marginBottom="163dp"
    android:background="#000000"
    android:scrollbarStyle="insideInset"
    >   
<LinearLayout  
  android:layout_width="wrap_content"
  android:layout_height="250dp"
  android:orientation="vertical"  
  >
  <TextView android:id="@+id/artistName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textColor="#ffffff"
        android:textSize="16px"
  />
  <ImageView 
        android:id="@+id/artistImageView"   
        android:layout_width="fill_parent" 
        android:layout_height="150dp"        
        android:layout_marginTop="2dp"
        android:paddingTop="10dp"
        android:paddingLeft="100dp"
        android:background="#000000"

        android:layout_marginRight="50dp"

  />

    <TextView
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:text="BIOGRAPHY"
        android:textStyle="bold"
        android:textColor="#ffffff"

        android:background="#000000"
        android:id="@+id/txt1"
    />          
    <ImageView
        android:src="@drawable/separator_bio"
        android:scaleType="fitXY"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"            
        android:background="#000000"
        android:id="@+id/sep1"
        android:paddingBottom="2dp"
    />        

    <TextView  
        android:id="@+id/artistView" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"         
        android:textStyle="bold"
        android:textColor="#eeeeee"              
        android:paddingLeft="20dp"                       
        android:background="#000000"                        
        android:lines="25"
      android:layout_marginRight="-20dp"  

    />
</LinearLayout>
</ScrollView>
</LinearLayout>
于 2012-11-29T09:05:34.220 回答