2011-11-08 89 views
3

之間我的活動的佈局必須如下:RelativeLayout的設計問題:滾動型中的RelativeLayout和一個按鈕

  • 屏幕被分成3個部分(3「行」)
  • 第一部分包括一個圖像在左邊,兩個TextView緊挨着它。
  • 第二部分是一個大文本,放入ScrollView中以便滾動。
  • 第三節只是一個按鈕,並且此按鈕必須始終位於屏幕的底部。

所以,第一和第三部分都必須固定,只有第二部分可以滾動。

這裏是我的代碼:

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

<RelativeLayout 
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"    
     android:layout_toRightOf="@id/imageView1" 
     android:text="TextView" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"    
     android:layout_toRightOf="@id/imageView1" 
     android:layout_below="@id/textView1" 
     android:text="TextView" /> 

</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/relativeLayout2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/relativeLayout1">  

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" >  

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text " /> 

    </ScrollView> 

</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/relativeLayout3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@id/relativeLayout2"> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 

</RelativeLayout> 

</RelativeLayout> 

的問題是很明顯的位置:

enter image description here

在中間部分的文本可以正常的滾動,但問題是,當佈局中的按鈕「開始」時,ScrollView不會「結束」。

+0

Downvoter(s) - explanation? – eightx2

回答

2

試試這個:

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

    <RelativeLayout 
     android:id="@+id/relativeLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:src="@drawable/ic_launcher" /> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/imageView1" 
      android:text="TextView" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/textView1" 
      android:layout_toRightOf="@id/imageView1" 
      android:text="TextView" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/relativeLayout2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_below="@id/relativeLayout1" > 

     <ScrollView 
      android:id="@+id/scrollView1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/textView3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text " /> 
     </ScrollView> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/relativeLayout3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@id/relativeLayout2" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button" /> 
    </RelativeLayout> 

</LinearLayout> 
+0

這個作品,非常感謝!我可以接受(3分鐘);) – eightx2

1

我只是想補充一點,你可以使用的RelativeLayout作爲最外層的佈局解決這個問題(而不是作爲的LinearLayout在Luksprogs例子)。假設您有兩個視圖:viewAbove和viewBelow,並且您想用另一個視圖填充兩個視圖之間的空間。將此添加到後面的視圖中:

android:layout_below="@id/viewAbove" 
android:layout_above="@id/viewBelow"