CardView with a smaller body and Image floating outside it











up vote
2
down vote

favorite












I am trying to create a CardView in Android that would have the image look like it is floating outside the box and the CardView box covering it would look smaller.



Since I do not know how to better describe it I found a similar design and tried to draw it on Paint.



enter image description here



The confusing part for me is to make the box appear smaller than the actual CardView is.










share|improve this question
























  • Check this question: stackoverflow.com/q/30640745/1574250
    – André Sousa
    Nov 9 at 13:29















up vote
2
down vote

favorite












I am trying to create a CardView in Android that would have the image look like it is floating outside the box and the CardView box covering it would look smaller.



Since I do not know how to better describe it I found a similar design and tried to draw it on Paint.



enter image description here



The confusing part for me is to make the box appear smaller than the actual CardView is.










share|improve this question
























  • Check this question: stackoverflow.com/q/30640745/1574250
    – André Sousa
    Nov 9 at 13:29













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I am trying to create a CardView in Android that would have the image look like it is floating outside the box and the CardView box covering it would look smaller.



Since I do not know how to better describe it I found a similar design and tried to draw it on Paint.



enter image description here



The confusing part for me is to make the box appear smaller than the actual CardView is.










share|improve this question















I am trying to create a CardView in Android that would have the image look like it is floating outside the box and the CardView box covering it would look smaller.



Since I do not know how to better describe it I found a similar design and tried to draw it on Paint.



enter image description here



The confusing part for me is to make the box appear smaller than the actual CardView is.







android xml cardview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 13:17

























asked Nov 9 at 13:07









Richard

347




347












  • Check this question: stackoverflow.com/q/30640745/1574250
    – André Sousa
    Nov 9 at 13:29


















  • Check this question: stackoverflow.com/q/30640745/1574250
    – André Sousa
    Nov 9 at 13:29
















Check this question: stackoverflow.com/q/30640745/1574250
– André Sousa
Nov 9 at 13:29




Check this question: stackoverflow.com/q/30640745/1574250
– André Sousa
Nov 9 at 13:29












4 Answers
4






active

oldest

votes

















up vote
0
down vote



accepted










Try out this code (for your item's layout file):



<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@android:color/holo_green_dark"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="25dp"
app:cardBackgroundColor="@android:color/holo_orange_light"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView One"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_marginStart="70dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView Two"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_marginStart="70dp"
android:layout_marginBottom="5dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView Three"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_marginStart="70dp"
android:layout_marginBottom="15dp" />

</LinearLayout>

</android.support.v7.widget.CardView>

<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="14dp"
android:layout_marginStart="12dp"
android:elevation="2dp"
android:background="@android:color/holo_red_dark"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>


Note: You must give more elevation to the ImageView that has to be placed above the CardView as because CardView has already got some its own elevation by default.



In your build.gradle (Module: app) file, under the dependencies add these two dependencies as follows:



dependencies {
// For ConstraintLayout:
implementation 'com.android.support.constraint:constraint-layout:1.1.3'

// For CardView:
implementation 'com.android.support:cardview-v7:27.1.1'
}


Screenshot (for the above code):



For screen size - 5.0 inch (1080 x 1920 pixels) [Device: Pixel 2]



enter image description here



I hope, this helps you.






share|improve this answer





















  • Thank you, this is pretty much what I wanted
    – Richard
    Nov 9 at 15:03










  • You're most welcome, Richard. ;-)
    – Nitin Gurbani
    Nov 9 at 15:03


















up vote
0
down vote













You should try a FrameLayout with the CardView and the ImageView. Then, give some margin to the CardView and you will get it.



Hope it helps.






share|improve this answer




























    up vote
    0
    down vote













    Just don't put the ImageView inside the CardView.



    Try something like this:



    <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top|start"
    android:elevation="16dp"
    />

    <CardView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:margin_top="8dp"
    android:margin_start="8dp">

    <!-- CardView contents -->
    </CardView>

    </FrameLayout>


    You'll need to adjust the dimensions to suit your layout.






    share|improve this answer























    • And what about the "floating" image?
      – Richard
      Nov 9 at 13:21










    • The ImageView is the floating image...
      – TheWanderer
      Nov 9 at 13:22


















    up vote
    0
    down vote













    <android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">



    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_margin="20dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:background="@color/cinza_claro"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:foregroundGravity="bottom"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>



    <ImageView
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_marginBottom="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:background="@color/red_app_accent"
    android:foregroundGravity="center"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>


    I think you can do like this example, using margin to adjust the image.



    Example






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226305%2fcardview-with-a-smaller-body-and-image-floating-outside-it%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote



      accepted










      Try out this code (for your item's layout file):



      <?xml version="1.0" encoding="utf-8"?>

      <android.support.constraint.ConstraintLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:background="@android:color/holo_green_dark"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

      <android.support.v7.widget.CardView
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_margin="25dp"
      app:cardBackgroundColor="@android:color/holo_orange_light"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintBottom_toBottomOf="parent">

      <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView One"
      android:textSize="20sp"
      android:textStyle="bold"
      android:textColor="@android:color/black"
      android:layout_marginStart="70dp"
      android:layout_marginTop="15dp"
      android:layout_marginBottom="5dp" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView Two"
      android:textSize="20sp"
      android:textStyle="bold"
      android:textColor="@android:color/black"
      android:layout_marginStart="70dp"
      android:layout_marginBottom="5dp" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView Three"
      android:textSize="20sp"
      android:textStyle="bold"
      android:textColor="@android:color/black"
      android:layout_marginStart="70dp"
      android:layout_marginBottom="15dp" />

      </LinearLayout>

      </android.support.v7.widget.CardView>

      <ImageView
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:layout_marginTop="14dp"
      android:layout_marginStart="12dp"
      android:elevation="2dp"
      android:background="@android:color/holo_red_dark"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent" />

      </android.support.constraint.ConstraintLayout>


      Note: You must give more elevation to the ImageView that has to be placed above the CardView as because CardView has already got some its own elevation by default.



      In your build.gradle (Module: app) file, under the dependencies add these two dependencies as follows:



      dependencies {
      // For ConstraintLayout:
      implementation 'com.android.support.constraint:constraint-layout:1.1.3'

      // For CardView:
      implementation 'com.android.support:cardview-v7:27.1.1'
      }


      Screenshot (for the above code):



      For screen size - 5.0 inch (1080 x 1920 pixels) [Device: Pixel 2]



      enter image description here



      I hope, this helps you.






      share|improve this answer





















      • Thank you, this is pretty much what I wanted
        – Richard
        Nov 9 at 15:03










      • You're most welcome, Richard. ;-)
        – Nitin Gurbani
        Nov 9 at 15:03















      up vote
      0
      down vote



      accepted










      Try out this code (for your item's layout file):



      <?xml version="1.0" encoding="utf-8"?>

      <android.support.constraint.ConstraintLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:background="@android:color/holo_green_dark"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

      <android.support.v7.widget.CardView
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_margin="25dp"
      app:cardBackgroundColor="@android:color/holo_orange_light"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintBottom_toBottomOf="parent">

      <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView One"
      android:textSize="20sp"
      android:textStyle="bold"
      android:textColor="@android:color/black"
      android:layout_marginStart="70dp"
      android:layout_marginTop="15dp"
      android:layout_marginBottom="5dp" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView Two"
      android:textSize="20sp"
      android:textStyle="bold"
      android:textColor="@android:color/black"
      android:layout_marginStart="70dp"
      android:layout_marginBottom="5dp" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView Three"
      android:textSize="20sp"
      android:textStyle="bold"
      android:textColor="@android:color/black"
      android:layout_marginStart="70dp"
      android:layout_marginBottom="15dp" />

      </LinearLayout>

      </android.support.v7.widget.CardView>

      <ImageView
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:layout_marginTop="14dp"
      android:layout_marginStart="12dp"
      android:elevation="2dp"
      android:background="@android:color/holo_red_dark"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent" />

      </android.support.constraint.ConstraintLayout>


      Note: You must give more elevation to the ImageView that has to be placed above the CardView as because CardView has already got some its own elevation by default.



      In your build.gradle (Module: app) file, under the dependencies add these two dependencies as follows:



      dependencies {
      // For ConstraintLayout:
      implementation 'com.android.support.constraint:constraint-layout:1.1.3'

      // For CardView:
      implementation 'com.android.support:cardview-v7:27.1.1'
      }


      Screenshot (for the above code):



      For screen size - 5.0 inch (1080 x 1920 pixels) [Device: Pixel 2]



      enter image description here



      I hope, this helps you.






      share|improve this answer





















      • Thank you, this is pretty much what I wanted
        – Richard
        Nov 9 at 15:03










      • You're most welcome, Richard. ;-)
        – Nitin Gurbani
        Nov 9 at 15:03













      up vote
      0
      down vote



      accepted







      up vote
      0
      down vote



      accepted






      Try out this code (for your item's layout file):



      <?xml version="1.0" encoding="utf-8"?>

      <android.support.constraint.ConstraintLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:background="@android:color/holo_green_dark"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

      <android.support.v7.widget.CardView
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_margin="25dp"
      app:cardBackgroundColor="@android:color/holo_orange_light"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintBottom_toBottomOf="parent">

      <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView One"
      android:textSize="20sp"
      android:textStyle="bold"
      android:textColor="@android:color/black"
      android:layout_marginStart="70dp"
      android:layout_marginTop="15dp"
      android:layout_marginBottom="5dp" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView Two"
      android:textSize="20sp"
      android:textStyle="bold"
      android:textColor="@android:color/black"
      android:layout_marginStart="70dp"
      android:layout_marginBottom="5dp" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView Three"
      android:textSize="20sp"
      android:textStyle="bold"
      android:textColor="@android:color/black"
      android:layout_marginStart="70dp"
      android:layout_marginBottom="15dp" />

      </LinearLayout>

      </android.support.v7.widget.CardView>

      <ImageView
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:layout_marginTop="14dp"
      android:layout_marginStart="12dp"
      android:elevation="2dp"
      android:background="@android:color/holo_red_dark"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent" />

      </android.support.constraint.ConstraintLayout>


      Note: You must give more elevation to the ImageView that has to be placed above the CardView as because CardView has already got some its own elevation by default.



      In your build.gradle (Module: app) file, under the dependencies add these two dependencies as follows:



      dependencies {
      // For ConstraintLayout:
      implementation 'com.android.support.constraint:constraint-layout:1.1.3'

      // For CardView:
      implementation 'com.android.support:cardview-v7:27.1.1'
      }


      Screenshot (for the above code):



      For screen size - 5.0 inch (1080 x 1920 pixels) [Device: Pixel 2]



      enter image description here



      I hope, this helps you.






      share|improve this answer












      Try out this code (for your item's layout file):



      <?xml version="1.0" encoding="utf-8"?>

      <android.support.constraint.ConstraintLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:background="@android:color/holo_green_dark"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

      <android.support.v7.widget.CardView
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_margin="25dp"
      app:cardBackgroundColor="@android:color/holo_orange_light"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintBottom_toBottomOf="parent">

      <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView One"
      android:textSize="20sp"
      android:textStyle="bold"
      android:textColor="@android:color/black"
      android:layout_marginStart="70dp"
      android:layout_marginTop="15dp"
      android:layout_marginBottom="5dp" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView Two"
      android:textSize="20sp"
      android:textStyle="bold"
      android:textColor="@android:color/black"
      android:layout_marginStart="70dp"
      android:layout_marginBottom="5dp" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView Three"
      android:textSize="20sp"
      android:textStyle="bold"
      android:textColor="@android:color/black"
      android:layout_marginStart="70dp"
      android:layout_marginBottom="15dp" />

      </LinearLayout>

      </android.support.v7.widget.CardView>

      <ImageView
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:layout_marginTop="14dp"
      android:layout_marginStart="12dp"
      android:elevation="2dp"
      android:background="@android:color/holo_red_dark"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent" />

      </android.support.constraint.ConstraintLayout>


      Note: You must give more elevation to the ImageView that has to be placed above the CardView as because CardView has already got some its own elevation by default.



      In your build.gradle (Module: app) file, under the dependencies add these two dependencies as follows:



      dependencies {
      // For ConstraintLayout:
      implementation 'com.android.support.constraint:constraint-layout:1.1.3'

      // For CardView:
      implementation 'com.android.support:cardview-v7:27.1.1'
      }


      Screenshot (for the above code):



      For screen size - 5.0 inch (1080 x 1920 pixels) [Device: Pixel 2]



      enter image description here



      I hope, this helps you.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 9 at 14:22









      Nitin Gurbani

      661215




      661215












      • Thank you, this is pretty much what I wanted
        – Richard
        Nov 9 at 15:03










      • You're most welcome, Richard. ;-)
        – Nitin Gurbani
        Nov 9 at 15:03


















      • Thank you, this is pretty much what I wanted
        – Richard
        Nov 9 at 15:03










      • You're most welcome, Richard. ;-)
        – Nitin Gurbani
        Nov 9 at 15:03
















      Thank you, this is pretty much what I wanted
      – Richard
      Nov 9 at 15:03




      Thank you, this is pretty much what I wanted
      – Richard
      Nov 9 at 15:03












      You're most welcome, Richard. ;-)
      – Nitin Gurbani
      Nov 9 at 15:03




      You're most welcome, Richard. ;-)
      – Nitin Gurbani
      Nov 9 at 15:03












      up vote
      0
      down vote













      You should try a FrameLayout with the CardView and the ImageView. Then, give some margin to the CardView and you will get it.



      Hope it helps.






      share|improve this answer

























        up vote
        0
        down vote













        You should try a FrameLayout with the CardView and the ImageView. Then, give some margin to the CardView and you will get it.



        Hope it helps.






        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote









          You should try a FrameLayout with the CardView and the ImageView. Then, give some margin to the CardView and you will get it.



          Hope it helps.






          share|improve this answer












          You should try a FrameLayout with the CardView and the ImageView. Then, give some margin to the CardView and you will get it.



          Hope it helps.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 13:14









          Juanje

          347212




          347212






















              up vote
              0
              down vote













              Just don't put the ImageView inside the CardView.



              Try something like this:



              <FrameLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">

              <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="top|start"
              android:elevation="16dp"
              />

              <CardView
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:margin_top="8dp"
              android:margin_start="8dp">

              <!-- CardView contents -->
              </CardView>

              </FrameLayout>


              You'll need to adjust the dimensions to suit your layout.






              share|improve this answer























              • And what about the "floating" image?
                – Richard
                Nov 9 at 13:21










              • The ImageView is the floating image...
                – TheWanderer
                Nov 9 at 13:22















              up vote
              0
              down vote













              Just don't put the ImageView inside the CardView.



              Try something like this:



              <FrameLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">

              <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="top|start"
              android:elevation="16dp"
              />

              <CardView
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:margin_top="8dp"
              android:margin_start="8dp">

              <!-- CardView contents -->
              </CardView>

              </FrameLayout>


              You'll need to adjust the dimensions to suit your layout.






              share|improve this answer























              • And what about the "floating" image?
                – Richard
                Nov 9 at 13:21










              • The ImageView is the floating image...
                – TheWanderer
                Nov 9 at 13:22













              up vote
              0
              down vote










              up vote
              0
              down vote









              Just don't put the ImageView inside the CardView.



              Try something like this:



              <FrameLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">

              <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="top|start"
              android:elevation="16dp"
              />

              <CardView
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:margin_top="8dp"
              android:margin_start="8dp">

              <!-- CardView contents -->
              </CardView>

              </FrameLayout>


              You'll need to adjust the dimensions to suit your layout.






              share|improve this answer














              Just don't put the ImageView inside the CardView.



              Try something like this:



              <FrameLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">

              <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="top|start"
              android:elevation="16dp"
              />

              <CardView
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:margin_top="8dp"
              android:margin_start="8dp">

              <!-- CardView contents -->
              </CardView>

              </FrameLayout>


              You'll need to adjust the dimensions to suit your layout.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 9 at 13:22

























              answered Nov 9 at 13:17









              TheWanderer

              5,70611025




              5,70611025












              • And what about the "floating" image?
                – Richard
                Nov 9 at 13:21










              • The ImageView is the floating image...
                – TheWanderer
                Nov 9 at 13:22


















              • And what about the "floating" image?
                – Richard
                Nov 9 at 13:21










              • The ImageView is the floating image...
                – TheWanderer
                Nov 9 at 13:22
















              And what about the "floating" image?
              – Richard
              Nov 9 at 13:21




              And what about the "floating" image?
              – Richard
              Nov 9 at 13:21












              The ImageView is the floating image...
              – TheWanderer
              Nov 9 at 13:22




              The ImageView is the floating image...
              – TheWanderer
              Nov 9 at 13:22










              up vote
              0
              down vote













              <android.support.constraint.ConstraintLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">



              <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="100dp"
              android:layout_margin="20dp"
              android:layout_marginBottom="8dp"
              android:layout_marginEnd="8dp"
              android:layout_marginLeft="8dp"
              android:layout_marginRight="8dp"
              android:layout_marginStart="8dp"
              android:layout_marginTop="8dp"
              android:background="@color/cinza_claro"
              app:layout_constraintBottom_toBottomOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              android:foregroundGravity="bottom"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toTopOf="parent"/>



              <ImageView
              android:layout_width="30dp"
              android:layout_height="30dp"
              android:layout_marginBottom="8dp"
              android:layout_marginLeft="8dp"
              android:layout_marginStart="8dp"
              android:layout_marginTop="8dp"
              android:background="@color/red_app_accent"
              android:foregroundGravity="center"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toTopOf="parent" />

              </android.support.constraint.ConstraintLayout>


              I think you can do like this example, using margin to adjust the image.



              Example






              share|improve this answer

























                up vote
                0
                down vote













                <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">



                <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_margin="20dp"
                android:layout_marginBottom="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:background="@color/cinza_claro"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                android:foregroundGravity="bottom"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"/>



                <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginBottom="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:background="@color/red_app_accent"
                android:foregroundGravity="center"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

                </android.support.constraint.ConstraintLayout>


                I think you can do like this example, using margin to adjust the image.



                Example






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  <android.support.constraint.ConstraintLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">



                  <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="100dp"
                  android:layout_margin="20dp"
                  android:layout_marginBottom="8dp"
                  android:layout_marginEnd="8dp"
                  android:layout_marginLeft="8dp"
                  android:layout_marginRight="8dp"
                  android:layout_marginStart="8dp"
                  android:layout_marginTop="8dp"
                  android:background="@color/cinza_claro"
                  app:layout_constraintBottom_toBottomOf="parent"
                  app:layout_constraintEnd_toEndOf="parent"
                  android:foregroundGravity="bottom"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toTopOf="parent"/>



                  <ImageView
                  android:layout_width="30dp"
                  android:layout_height="30dp"
                  android:layout_marginBottom="8dp"
                  android:layout_marginLeft="8dp"
                  android:layout_marginStart="8dp"
                  android:layout_marginTop="8dp"
                  android:background="@color/red_app_accent"
                  android:foregroundGravity="center"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toTopOf="parent" />

                  </android.support.constraint.ConstraintLayout>


                  I think you can do like this example, using margin to adjust the image.



                  Example






                  share|improve this answer












                  <android.support.constraint.ConstraintLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">



                  <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="100dp"
                  android:layout_margin="20dp"
                  android:layout_marginBottom="8dp"
                  android:layout_marginEnd="8dp"
                  android:layout_marginLeft="8dp"
                  android:layout_marginRight="8dp"
                  android:layout_marginStart="8dp"
                  android:layout_marginTop="8dp"
                  android:background="@color/cinza_claro"
                  app:layout_constraintBottom_toBottomOf="parent"
                  app:layout_constraintEnd_toEndOf="parent"
                  android:foregroundGravity="bottom"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toTopOf="parent"/>



                  <ImageView
                  android:layout_width="30dp"
                  android:layout_height="30dp"
                  android:layout_marginBottom="8dp"
                  android:layout_marginLeft="8dp"
                  android:layout_marginStart="8dp"
                  android:layout_marginTop="8dp"
                  android:background="@color/red_app_accent"
                  android:foregroundGravity="center"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toTopOf="parent" />

                  </android.support.constraint.ConstraintLayout>


                  I think you can do like this example, using margin to adjust the image.



                  Example







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 9 at 15:46









                  Hallefy Ferreira

                  112




                  112






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226305%2fcardview-with-a-smaller-body-and-image-floating-outside-it%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Landwehr

                      Reims

                      Schenkenzell