2012-09-18 42 views
6

我目前使用的是一個包含ScrollView內部的RelativeLayout的佈局。Android paddingBottom無法工作沒有填充頂部

我想要的RelativeLayout被包含在從滾動型的底部,所以它不重疊我有它背後的背景5DP走,要達到這個我就是用這個XML:

<ScrollView 
    android:id="@+id/scrollView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignTop="@+id/backgroundView1" 
    android:fadingEdge="none" 
    android:scrollbars="none" 
    android:paddingTop="5dp" 
    android:paddingBottom="5dp"> 

    <RelativeLayout 
     android:id="@+id/innerLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    </RelativeLayout> 
</ScrollView> 

這完美地工作,但是我不再需要頂部的填充。在刪除paddingTop行時,paddingBottom不再起作用。即使我將paddingBottom設置爲100dp,它也不會影響我的佈局。

我試圖paddingTop =「0dp」,但這並沒有解決任何問題,看來當paddingTop高於0

任何paddingBottom來只會工作,有任何想法,爲什麼paddingBottom來不無paddingTop工作?

+1

我想你的代碼,並當上填充是零它的工作原理。我使用相對佈局作爲父佈局。 – Gan

回答

0

你寫XML屬性機器人:layout_alignParentBottom =「真」所以你滾動型將始終會保持一致底部

刪除android:layout_alignParentBottom =「true」並重試。

0

使用這種佈局的scrollview和根據您的需要改變..不使用scrollview內的相對佈局。 在這裏,您可以設置在圖像中的任何類型的高度,你仍然會看到在底部填充沒有任何paddingtop

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

    <ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="#cccccc" 
     android:paddingBottom="5dp" 
     android:scrollbars="none" > 

     <LinearLayout 
      android:id="@+id/innerLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="700dp" 
       android:background="@android:color/transparent" 
       android:scaleType="fitXY" 
       android:src="@drawable/image2" /> 
     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 
0

可以使用

android:layout_marginTop="10dip" 

android:layout_marginBottom="20dip" 
-1

這是頂部和底部具有(5dp)空間

<ScrollView 
    android:id="@+id/scrollView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignTop="@+id/backgroundView1" 
    android:fadingEdge="none" 
    android:scrollbars="none" 
    android:paddingTop="5dp" 
    android:paddingBottom="5dp"> 

    <RelativeLayout 
     android:id="@+id/innerLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:layout_marginBottom="5dp"> 
    </RelativeLayout> 
</ScrollView> 

這對於具有頂部,底部,左側(5 DP)的空間,和右

<ScrollView 
    android:id="@+id/scrollView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignTop="@+id/backgroundView1" 
    android:fadingEdge="none" 
    android:scrollbars="none" 
    android:paddingTop="5dp" 
    android:paddingBottom="5dp"> 

    <RelativeLayout 
     android:id="@+id/innerLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp"> 
    </RelativeLayout> 
</ScrollView>