【问题标题】:Android Padding not affecting layoutAndroid Padding 不影响布局
【发布时间】:2014-01-15 09:46:25
【问题描述】:

好的,我开始了解 XML 如何在 Android 界面上运行,但我遇到了一个问题...

我只有一个带有 RelativeLayout 的 Horizo​​ntalScrollView,稍后我将在其中放置其他视图。如您所见,Horizo​​ntalScrollView 位于一个按钮上方,另一个按钮下方。我喜欢它的放置位置,但我不希望它正好在按钮的正上方和正下方。我想要一些间距(填充)。我试过添加填充,但它似乎没有效果......

这是我尝试的 XML:

    <HorizontalScrollView
        android:id="@+id/scrollview_xyzInfo"
        android:layout_width="match_parent"
        android:layout_height="130dp"
        android:layout_above="@+id/button_refresh"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/button_mySettings"
        android:paddingTop="20dp"
        android:paddingBottom="20dp"
        android:background="@drawable/refresh_selector" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent" >
        </RelativeLayout>

 </HorizontalScrollView>

任何帮助将不胜感激:-)

【问题讨论】:

  • 只需在 ScrollView 中添加一些底部和顶部边距

标签: java android xml layout padding


【解决方案1】:

没关系!像这样分隔两个视图时使用边距:

android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"

答案在: Padding not working Android

【讨论】:

  • 如果您要在左、右、上和下添加相同的边距,您可以说 android:layout_margin="10dp" :)
【解决方案2】:

填充和边距仅适用于 LinearLayout。您使用的是哪种布局?

【讨论】:

  • 这可能更适合作为评论而不是问题的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-09
相关资源
最近更新 更多