2012-09-18 49 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>