0

Also outer view should have rounded corners.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ffffff"></solid>
    <corners android:radius="10dp" />
    <stroke
        android:width="@dimen/dimen_1"
        android:color="#1877ee" />
</shape>

codezlab card image

satvinder singh
  • 1,152
  • 1
  • 12
  • 22

3 Answers3

0

Why not just use a layout over another layout?

For example, a parent linear layout overall and two children linear layouts with equal weights and different backgrounds:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"> 

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical"
    android:background="#FFEB3B">
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical"
    android:background="#CC2323">
</LinearLayout>

</LinearLayout>

enter image description here

Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
  • as i mentioned need rounded corners too and outer container should have height wrap_content – satvinder singh Feb 20 '20 at 15:24
  • For getting a colored background with rounded colors look at this question and the various answers: https://stackoverflow.com/questions/8930555/android-drawable-with-rounded-corners-at-the-top-only And if you want the outer container to be wrap_content, then why not just change its height attribute to that? If the entire layout needs to have rounded corners, you probably want to look into CardViews: https://developer.android.com/reference/android/support/v7/widget/CardView – michpohl Feb 20 '20 at 17:30
0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:background="@drawable/round_corners"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:weightSum="2"> 

    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_weight="1"
      android:orientation="vertical"
      android:background="@color/upper_one"> //code for layout for adjusting height </LinearLayout>

   <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_weight="1"
     android:orientation="vertical"
     android:background="@color/lower_color"> //code for layout for adjusting height</LinearLayout>
</LinearLayout>

You can fix the height or use wrap content to height and adjust view height inside linearlayouts

Prakash Reddy
  • 944
  • 10
  • 20
0

May be you can use custom drawable:

Make new drawable (border_up.xml) using this code:

<corners android:topLeftRadius="10dp"
    android:topRightRadius="10dp"
    android:bottomLeftRadius="0dp"
    android:bottomRightRadius="0dp" />
<solid
    android:color="@color/colorPrimary"/>

And border_down.xml :

<corners android:topLeftRadius="0dp"
    android:topRightRadius="0dp"
    android:bottomLeftRadius="10dp"
    android:bottomRightRadius="10dp" />
<solid
    android:color="@color/colorAccent"/>

In your layout, make linear layout or textview that using above drawable :

<LinearLayout
    android:weightSum="2"
    android:orientation="vertical"
    android:layout_width="120dp"
    android:layout_height="200dp"
    android:layout_marginTop="50dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="@color/colorWhite"
        android:gravity="center_horizontal|center_vertical"
        android:background="@drawable/border_up"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/colorWhite"
        android:gravity="center_horizontal|center_vertical"
        android:background="@drawable/border_down"
        android:layout_weight="1"
        android:text="TextView" />
</LinearLayout>

enter image description here

Rembulan Moon
  • 338
  • 3
  • 11