Layout with background corner radius with elements inside

border-radius
border-radius css circle
border radius generator
border-radius not working
border-corner-shape css
border-radius top-left and right
css rounded corners
border-radius mdn

I have a layout with a custom background with corner radius

The code of the drawable background is

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle">
<corners
        android:bottomLeftRadius="7dp"
        android:bottomRightRadius="7dp"
        android:topLeftRadius="7dp"
        android:topRightRadius="7dp"
/>
<stroke
        android:width="1dp"
        android:color="@color/dusky_blue"/>
<solid
    android:color="@color/white"/>
</shape>

When I set a background color of an element inside this layout, the corners of the parent are overlapped.

Is there a simple way to fit the child background to the parent corner (without making a customer drawable background) ?

Thank you

This will fix your issue

Instead of setting background color create two other xml in drawable and set it in the background when required.

Example :

  1. left_curve_shape.xml

    <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:bottomLeftRadius="7dp" android:topLeftRadius="7dp"/> <solid android:color="@color/your_color_name"/> </shape>

  2. right_curve_shape.xml

    <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:bottomRightRadius="7dp" android:topRightRadius="7dp"/> <solid android:color="@color/your_color_name"/> </shape>

And Now Finally

Set these drawables instead of color like

android:background="@drawable/left_curve_shape"
android:background="@drawable/right_curve_shape"

You can also set background from java code.

Hope it will fix your issue

border-radius, You can give any element "rounded corners" by applying a border-radius through CSS. .round { border-radius: 10px; /* Prevent background color leak outs Four values apply to the top-left , top-right , bottom-right , bottom-left corner in that order. ShopTalk is a podcast all about front-end web design and development. Here is the corner radius --> <corners android:radius="10dp" > </corners> </shape> And keep this drawable as background for the view to which you want to keep rounded corner border. Let’s keep it for a LinearLayout

Do not set the background directly because it's not a simple Drawable. You can use android:backgroundTint="#000" in XML, you can also try these java methods

public static void changeGradientDrawableBackgroundColor(View view, int color) {
    GradientDrawable gd = (GradientDrawable) view.getBackground();
    gd.setColor(color);
}

public static void changeStrokeColor(View view, int color) {
    GradientDrawable gd = (GradientDrawable) view.getBackground();
    gd.setStroke(2, color);
}

public static void changeTransitionDrawableColor(TransitionDrawable td, int color, int index) {
    td.getDrawable(index).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}

or you can simply use this library for making rounded corner layouts

Rounded Korner Layouts

CSS Rounded Corners, Tip: This property allows you to add rounded corners to elements! Here are three examples: 1. Rounded corners for an element with a specified background  Rounded Corners. In this quick article we will see how to add Rounded corners to Views and Layouts. This can be done on Layout XML or Programatically. Here we will see both the ways. Rounded Border with Transparent Inside. Create an xml inside Drawable Folder with below code. Name it rounded_red_border.xml

Your stroke width is 1dp:

<stroke
        android:width="1dp"
        android:color="@color/dusky_blue"/>

With that being said, it looks like you would need to add a padding of 1dp or more to your tab layout so that your border isn't covered by your content background. So the element backgrounds will begin at least 1dp inside of your tab layout.

CSS border-radius property, grid-template grid-template-areas grid-template-columns grid-template-rows Tip: This property allows you to add rounded corners to elements! Note: The four values for each radius are given in the order top-left, top-right, bottom-right, bottom-left. Set rounded corners for an element with a background color:. I want to create a layout with rounded corners and a filled color background. This is my layout: &lt;LinearLayout android:layout_width="match_parent" android:layout_height="210dp" and

    *Follow the blew steps to do the expected output...*   

  left_bg.xml
               <?xml version="1.0" encoding="UTF-8"?>
              <shape xmlns:android="http://schemas.android.com/apk/res/android">
                  <solid android:color="@color/colorPrimary"/>
                  <stroke android:width="1dp"
                          android:color="#00000000" />

                  <corners android:topLeftRad`enter code here`ius="10dp"
                           android:bottomLeftRadius="10dp"/>
                  <padding android:left="0dp"
                           android:top="0dp"
                           android:right="0dp"
                           android:bottom="0dp" />
              </shape>

 right_bg.xml
              <?xml version="1.0" encoding="UTF-8"?>
              <shape xmlns:android="http://schemas.android.com/apk/res/android">
                  <solid android:color="@color/colorPrimary"/>
                  <stroke android:width="1dp"
                          android:color="#00000000" />

                  <corners android:topRightRadius="10dp"
                           android:bottomRightRadius="10dp"/>
                  <padding android:left="0dp"
                           android:top="0dp"
                           android:right="0dp"
                           android:bottom="0dp" />
              </shape>


        *Layout design*
        <LinearLayout android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:weightSum="2"
                      android:background="@drawable/layout_bg"
                      android:layout_margin="10dp"
                      android:id="@+id/llIeltsSocreType">

            <TextView
                    android:id="@+id/tvAcademicScore"
                    android:layout_width="50dp"
                      android:layout_height="50dp"
                      android:text="Academic"
                      android:textColor="#fff"
                      android:background="@drawable/left_bg"
                      android:gravity="center"
                      android:layout_weight="1"
                      android:textSize="25sp"/>


            <TextView
                    android:id="@+id/tvGeneralScore"
                    android:layout_width="50dp"
                      android:layout_height="50dp"
                      android:text="General"
                      android:textColor="@color/colorPrimaryDark"
                      android:gravity="center"
                      android:textSize="25sp"
                      android:layout_weight="1"/>

        </LinearLayout>


programmatically manage your click event and set your layout corner and background with text color



               if(getSharedString(select_type).equals("academic")  ){
                tvAcademicScore.setBackgroundResource(R.drawable.left_bg)
                tvGeneralScore.setBackgroundResource(R.color.colorTransparent)

                tvAcademicScore.setTextColor(ContextCompat.getColor(applicationContext, R.color.colorWhite))
                tvGeneralScore.setTextColor(ContextCompat.getColor(applicationContext, R.color.colorPrimaryDark))

            }else if(getSharedString(select_type).equals("general")){
                tvAcademicScore.setBackgroundResource( R.color.colorTransparent)
                tvGeneralScore.setBackgroundResource( R.drawable.right_bg)

                tvGeneralScore.setTextColor(ContextCompat.getColor(applicationContext, R.color.colorWhite))
                tvAcademicScore.setTextColor(ContextCompat.getColor(applicationContext, R.color.colorPrimaryDark))

            }

border-radius, The border-radius CSS property rounds the corners of an element's The radius applies to the whole background , even if the element has no border; a radius to use for the border in the bottom-right corner of the element's  If you want to change the border-radius, you have to change it for each sub element. To avoid this, you can use the following: div.parent {border-radius: 5px; …} div.parent div.child {border-radius: inherit} You have to leave the border-radius attribute, but you can use “inherit”. If you want to change 5px to 3px, you only have to change

How to create fancy corners with CSS, In this tutorial, we'll first demonstrate how to create rounded corners and then show how you absolute elements */ width: 200px; height: 80px; background-​color: #522d5b; } This type of design is perfect for speech bubbles. For this one, you can remove the background shape from ImageView and set only the top corners to be rounded from Java/Kotlin code like this, val image = findViewById<ImageView>(R.id.image) val

Pro Silverlight 3 in C#, By default, the Background of a layout panel is set to a null reference, which is equivalent to this: <Grid However, there's an element that fills in the gap–the Border. The greater the CornerRadius, the more dramatic the rounding effect is​. When you add Auto Layout to a frame, the items inside are stacked next to each other (either vertically or horizontally). The frame's size is then determined by the total size of the items within it. Auto Layout frames can have their own padding, fill, stroke and corner radius, so you can create buttons without adding additional layers.

Pro Silverlight 3 in VB, By default, the Background of a layout panel is set to a null reference (Nothing), which is equivalent to However, there's an element that fills in the gap–the Border. The greater the CornerRadius, the more dramatic the rounding effect is​. Additionally ClipToBounds=True is not needed for most elements because their implementations dont allow their content's layout to spill anyway. The most notable exception is Canvas. Finally Border considers the rounded corners to be drawings inside the bounds of its layout.

Comments
  • pls share your layout xml code
  • Make round corners to the tabLayout container