2012-06-09 27 views
44

Tôi đang gặp vấn đề lạ và không chắc chắn cách khắc phục. Tôi có một RelativeLayout bên trong một ScrollView và scrollView này có chiều cao của nó được thiết lập để fill_parent. Vì vậy, các RelativeLayout. Tuy nhiên, nội dung không làm đầy toàn bộ màn hình và nó sẽ chỉ đến wrap_content của bố cục cuối cùng bên trong RelativeLayout này.Không thể thay đổi kích thước RelativeLayout bên trong ScrollView để lấp đầy toàn bộ màn hình

Đây là mã của tôi:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res/com.pontai" 
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <RelativeLayout 
      android:id="@+id/relativeLayout2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <LinearLayout 
       android:id="@+id/linearLayout1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@+id/relativeLayout3" 
       android:layout_alignParentTop="true" 
       android:layout_alignRight="@+id/relativeLayout5" 
       android:layout_marginTop="5dp" 
       android:orientation="horizontal" > 

       <TextView 
        android:id="@+id/textView1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:text="How much points you have here:" 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <TextView 
        android:id="@+id/textViewTotalPoints1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:text="120" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 
      </LinearLayout> 

      <RelativeLayout 
       android:id="@+id/relativeLayout4" 
       android:layout_width="wrap_content" 
       android:layout_height="80dp" 
       android:layout_alignLeft="@+id/relativeLayout3" 
       android:layout_below="@+id/linearLayout1" 
       android:layout_marginTop="5dp" 
       android:layout_toLeftOf="@+id/textView7" 
       android:orientation="vertical" > 

       <TextView 
        android:id="@+id/textView3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="5dp" 
        android:text="Ratings" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 

       <TextView 
        android:id="@+id/textViewPositivePoints" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <ImageView 
        android:id="@+id/imageView2" 
        android:layout_width="25dp" 
        android:layout_height="25dp" 
        android:layout_below="@+id/textView3" 
        android:layout_toLeftOf="@+id/textView3" 
        android:src="@drawable/thumbs_up_focused" /> 

       <TextView 
        android:id="@+id/textViewNegativePoints" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignRight="@+id/textView3" 
        android:layout_centerVertical="true" 
        android:layout_marginRight="3dp" 
        android:text="22" 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <TextView 
        android:id="@+id/textView5" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignBaseline="@+id/textViewNegativePoints" 
        android:layout_alignBottom="@+id/textViewNegativePoints" 
        android:layout_alignLeft="@+id/textView3" 
        android:layout_marginLeft="3dp" 
        android:text="33" 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <ImageView 
        android:id="@+id/imageView3" 
        android:layout_width="25dp" 
        android:layout_height="25dp" 
        android:layout_alignTop="@+id/imageView2" 
        android:layout_toRightOf="@+id/textViewNegativePoints" 
        android:src="@drawable/thumbs_down_focused" /> 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/relativeLayout5" 
       android:layout_width="95dp" 
       android:layout_height="80dp" 
       android:layout_alignRight="@+id/relativeLayout3" 
       android:layout_alignTop="@+id/relativeLayout4" 
       android:layout_toRightOf="@+id/textView7" 
       android:orientation="vertical" > 

       <TextView 
        android:id="@+id/textView4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="5dp" 
        android:text="Comments" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 

       <ImageView 
        android:id="@+id/imageView1" 
        android:layout_width="50dp" 
        android:layout_height="50dp" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true" 
        android:src="@drawable/speech_bubble" /> 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/relativeLayout3" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/relativeLayout4" 
       android:layout_centerHorizontal="true" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:layout_marginTop="10dp" > 

       <TextView 
        android:id="@+id/textViewOfferName" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="10dp" 
        android:text="Offer Name" 
        android:textAppearance="?android:attr/textAppearanceLarge" /> 

       <TextView 
        android:id="@+id/textViewBusinessName" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="35dp" 
        android:text="Business Name" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 

       <TextView 
        android:id="@+id/textViewBusinessAddress" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="60dp" 
        android:text="Business Address" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 

       <TextView 
        android:id="@+id/textViewNull1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="80dp" 
        android:textAppearance="?android:attr/textAppearanceLarge" /> 

       <TextView 
        android:id="@+id/textViewTotalPoints" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/textViewNull1" 
        android:layout_centerHorizontal="true" 
        android:text="0/0" 
        android:textAppearance="?android:attr/textAppearanceLarge" /> 

       <Button 
        android:id="@+id/buttonUseNow" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/textViewTotalPoints" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="10dp" 
        android:text="@string/offer_details_use_now" /> 

       <TextView 
        android:id="@+id/textView2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:layout_below="@+id/buttonUseNow" 
        android:layout_marginTop="10dp" 
        android:text="@string/_terms_and_conditions_" 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <TextView 
        android:id="@+id/textViewTermsConditions" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:layout_below="@+id/textView2" 
        android:layout_marginTop="2dp" 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 
      </RelativeLayout> 

      <TextView 
       android:id="@+id/textView7" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignBottom="@+id/relativeLayout5" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="30dp" 
       android:text="e" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:visibility="invisible" /> 
     </RelativeLayout> 
    </ScrollView> 

</RelativeLayout> 

Bất cứ ai cũng có những ý tưởng như thế nào tôi có thể làm cho RelativeLayout2 có chiều cao giống như scrollview, ý nghĩa, tôi muốn nó đạt đến dưới cùng của màn hình?

Cảm ơn và kính trọng, Felipe

Trả lời

135

Tôi đã gặp phải vấn đề này trước đây. Chỉ cần sử dụng android:fillViewport="true" trong scrollview của bạn và nó sẽ lấp đầy màn hình.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/scrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" > 
+0

lấy từ câu trả lời của tôi tại http://stackoverflow.com/questions/10312272/layout-weight-is-not-work-in-scrollview/10312631#10312631 – Akhil

+0

Và, nó làm việc! :) Cảm ơn rất nhiều, Akhil! –

+1

@Akhil: vâng nó hoạt động khi bạn thêm dòng đó! nhưng việc bổ sung câu lệnh đó giải quyết vấn đề như thế nào? – Ashwin

Các vấn đề liên quan