Back

Android 笔记: 设置 view的 上下边距. 设置border.

发布时间: 2016-09-03 08:18:00

设置 view的 border: 

refer to http://stackoverflow.com/questions/10457135/how-to-add-border-around-linear-layout-except-at-the-bottom

1. 建立一个新的XML文件:    res/drawable/border.xml

 <?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item> 
    <shape android:shape="rectangle">
      <solid android:color="#FF0000" />  
    </shape>
  </item>   
    <item android:left="5dp" android:right="5dp"  android:top="5dp" >   
     <shape android:shape="rectangle"> 
      <solid android:color="#000000" />
    </shape>
   </item>      
 </layer-list> 

2. 在对应的xml 中, 使用它:

android:background="@drawable/border"

设置View的上下边距

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

让图片在竖直方向居中: 

android:layout_centerInParent="true"

Back