How can I create a border around an Android LinearLayout?

前端 未结 9 994
长发绾君心
长发绾君心 2020-12-22 20:33

I have one big layout, and one smaller layout inside of it.

How do I create a line border around the small layout?

相关标签:
9条回答
  • 2020-12-22 21:31

    you can do it Pragmatically also

      GradientDrawable gradientDrawable=new GradientDrawable();
       gradientDrawable.setStroke(4,getResources().getColor(R.color.line_Input));
    

    Then set the background of layout as :

    LinearLayout layout = (LinearLayout ) findViewById(R.id.ayout); layout .setBackground(gradientDrawable);
    
    0 讨论(0)
  • 2020-12-22 21:32

    Creat XML called border.xml in drawable folder as below :

    <?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>
    

    then add this to linear layout as backgound as this:

         android:background="@drawable/border"
    
    0 讨论(0)
  • 2020-12-22 21:36

    Try This in your res/drawable

        <?xml version="1.0" encoding="UTF-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
      <shape
        android:shape="rectangle">
        <padding android:left="15dp"
            android:right="15dp"
            android:top="15dp"
            android:bottom="15dp"/>
        <stroke android:width="10dp"
            android:color="@color/colorPrimary"/>
      </shape>
    </item><item android:left="-5dp"
            android:right="-5dp"
            android:top="-5dp"
            android:bottom="-5dp">
      <shape android:shape="rectangle">
        <solid android:color="@color/background" />
      </shape></item></layer-list>
    
    0 讨论(0)
提交回复
热议问题