使ScrollView适合整个活动

时间:2015-05-28 12:26:20

标签: android scrollview android-5.0-lollipop material-design

我找不到这个问题的任何答案,我有一个活动,其布局包含(按此顺序)TextViewImageViewScrollView。在这个ScrollView中,有一个RelativeLayout包含几个内容。这是我的代码

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background= "#7a9965"
tools:context="pact.smartpen.AboutActivity">

<TextView
    android:text="À propos de"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView"
    android:layout_centerHorizontal="true"
    android:typeface="serif"
    android:textSize="30dp"/>

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="250dp"
    android:layout_height="150dp"
    android:src="@drawable/sp"
    android:layout_below="@+id/textView"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:id="@+id/scrollView"
    android:layout_below="@+id/imageView1">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">


            <TextView
                android:text="foo foo foo foo foo foo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/textView2"
                android:gravity="center_horizontal"
                android:typeface="serif"
                android:textSize="24dp"
                android:layout_alignParentEnd="true" />

            <TextView
                android:text="bar bar bar bar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoLink="web"
                android:id="@+id/textView3"
                android:layout_centerHorizontal="true"
                android:gravity="center_horizontal"
                android:layout_below="@id/textView2"
                android:typeface="serif"
                android:textSize="18dp"/>
        </RelativeLayout>



</ScrollView>

问题是ScrollView无法正确显示屏幕。

2 个答案:

答案 0 :(得分:1)

<RelativeLayout>

中删除此内容
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"

该代码为您的活动提供了一个完整的填充。

希望它有所帮助!

答案 1 :(得分:1)

import akka.util.ByteString
import akka.stream.scaladsl.Source
import java.io.PipedInputStream
import java.io.PipedOutputStream
import akka.stream.io.OutputStreamSink
import java.io.BufferedReader
import java.io.InputStreamReader
import akka.actor.ActorSystem
import akka.stream.ActorFlowMaterializer

object PipedStream extends App{
  implicit val system = ActorSystem("flowtest")
  implicit val mater = ActorFlowMaterializer()

  val lines = for(i <- 1 to 100) yield ByteString(s"This is line $i\n")
  val source = Source(lines)

  val pipedIn = new PipedInputStream()
  val pipedOut = new PipedOutputStream(pipedIn)      
  val flow = source.to(OutputStreamSink(() => pipedOut))
  flow.run()

  val reader = new BufferedReader(new InputStreamReader(pipedIn))
  var line:String = reader.readLine
  while(line != null){
    println(s"Reader received line: $line")
    line = reader.readLine
  }           
}