How to add an ImageView outside and to the left of a Card?











up vote
0
down vote

favorite












This is what I'm trying to achieve



enter image description here



And this is what I have so far and the code below is the code for this screenshot



enter image description here



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.v7.widget.CardView
android:layout_width="270dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="10dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">

<ImageView
android:id="@+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerVertical="true" />

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/imageView"
android:textColor="#000000"
android:textSize="40sp" />
</RelativeLayout>

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


Basically, I can't figure out how to get the image outside but still touching the card. Any help is appreciated, thanks.










share|improve this question




























    up vote
    0
    down vote

    favorite












    This is what I'm trying to achieve



    enter image description here



    And this is what I have so far and the code below is the code for this screenshot



    enter image description here



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
    android:layout_width="270dp"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:layout_margin="10dp">

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp">

    <ImageView
    android:id="@+id/imageView"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_centerVertical="true" />

    <TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_toRightOf="@id/imageView"
    android:textColor="#000000"
    android:textSize="40sp" />
    </RelativeLayout>

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


    Basically, I can't figure out how to get the image outside but still touching the card. Any help is appreciated, thanks.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      This is what I'm trying to achieve



      enter image description here



      And this is what I have so far and the code below is the code for this screenshot



      enter image description here



      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">

      <android.support.v7.widget.CardView
      android:layout_width="270dp"
      android:layout_height="wrap_content"
      android:layout_gravity="right"
      android:layout_margin="10dp">

      <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="16dp">

      <ImageView
      android:id="@+id/imageView"
      android:layout_width="80dp"
      android:layout_height="80dp"
      android:layout_centerVertical="true" />

      <TextView
      android:id="@+id/title"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="5dp"
      android:layout_toRightOf="@id/imageView"
      android:textColor="#000000"
      android:textSize="40sp" />
      </RelativeLayout>

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


      Basically, I can't figure out how to get the image outside but still touching the card. Any help is appreciated, thanks.










      share|improve this question















      This is what I'm trying to achieve



      enter image description here



      And this is what I have so far and the code below is the code for this screenshot



      enter image description here



      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">

      <android.support.v7.widget.CardView
      android:layout_width="270dp"
      android:layout_height="wrap_content"
      android:layout_gravity="right"
      android:layout_margin="10dp">

      <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="16dp">

      <ImageView
      android:id="@+id/imageView"
      android:layout_width="80dp"
      android:layout_height="80dp"
      android:layout_centerVertical="true" />

      <TextView
      android:id="@+id/title"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="5dp"
      android:layout_toRightOf="@id/imageView"
      android:textColor="#000000"
      android:textSize="40sp" />
      </RelativeLayout>

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


      Basically, I can't figure out how to get the image outside but still touching the card. Any help is appreciated, thanks.







      android imageview android-cardview






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 3:19









      Ayush Khare

      1,101620




      1,101620










      asked Nov 9 at 3:15









      Sixteen

      104




      104
























          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You can use FrameLayout and elevation to fulfill your target.



          According to the documentation of FrameLayout




          Child views are drawn in a stack, with the most recently added child
          on top




          You need to play with the elevation of the ImageView to bring it above the CardView.



          This is what I have achieved: You can then modify your paddings/margins according to design.



          enter image description here



          Code:



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

          <FrameLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
          <android.support.v7.widget.CardView
          app:cardCornerRadius="4dp"
          app:cardBackgroundColor="@android:color/holo_blue_bright"
          android:layout_width="308dp"
          android:layout_height="112dp"
          android:layout_gravity="right"
          android:layout_margin="10dp">

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

          <TextView
          android:layout_marginStart="40dp"
          android:id="@+id/title"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="5dp"
          android:paddingLeft="8dp"
          android:text="EARTH"
          android:textColor="#000000"
          android:textSize="70sp" />
          </LinearLayout>

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

          <ImageView
          android:src="@drawable/planet"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_margin="16dp"
          android:elevation="2dp" />
          </FrameLayout>
          </LinearLayout>





          share|improve this answer























          • Thanks, but I changed one line in your code so it could work with my app which was I replaced android:src="@drawable/planet" with android:id="@+id/imageView" and when I run the app it now only displays one card! How would this work with lots of cards?
            – Sixteen
            Nov 9 at 5:30










          • You can very well keep the android:id="@+id/imageView" to have a handle to the image view. My android:src="@drawable/planet" was just a static place holder drawable (the pink circle image) for the image view. These two are entirely different. You can programmatically set the drawable/image resource on the imageView later in your code. This layout is a child layout of your recyclerView. You have to have a adapter for populating your recyclerView with a number of items
            – mukut bhattacharjee
            Nov 9 at 5:52




















          up vote
          0
          down vote













          Try this layout



          <?xml version="1.0" encoding="utf-8"?>
          <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:card_view="http://schemas.android.com/apk/res-auto"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:id="@+id/activity_main"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

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

          <android.support.v7.widget.CardView
          android:id="@+id/first"
          app:cardBackgroundColor="@android:color/white"
          app:cardCornerRadius="@dimen/cardview_default_radius"
          app:cardElevation="4dp"
          android:layout_width="match_parent"
          android:layout_height="80dp"
          android:layout_marginLeft="50dp"
          card_view:cardUseCompatPadding="true">

          <RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginLeft="32dp">

          <TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="TEXT"
          android:textSize="18sp"/>

          </RelativeLayout>

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

          </FrameLayout>

          <ImageView
          android:layout_width="50dp"
          android:layout_height="50dp"
          android:layout_marginLeft="32dp"
          android:background="#000000"
          android:layout_marginTop="15dp"
          android:contentDescription="@null"/>

          </RelativeLayout>


          Result:



          enter image description here






          share|improve this answer




























            up vote
            0
            down vote













            You can use ConstraintLayout cool property for doing this easily



            Xml snippet :



            <?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:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_margin="10dp"
            app:cardUseCompatPadding="true">
            <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginStart="35dp"
            app:cardBackgroundColor="@color/cardview_dark_background"
            app:cardUseCompatPadding="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
            <de.hdodenhof.circleimageview.CircleImageView
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:src="@android:drawable/ic_dialog_info"
            android:translationZ="2dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />


            </android.support.constraint.ConstraintLayout>


            Output View : enter image description here






            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%2f53219343%2fhow-to-add-an-imageview-outside-and-to-the-left-of-a-card%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote



              accepted










              You can use FrameLayout and elevation to fulfill your target.



              According to the documentation of FrameLayout




              Child views are drawn in a stack, with the most recently added child
              on top




              You need to play with the elevation of the ImageView to bring it above the CardView.



              This is what I have achieved: You can then modify your paddings/margins according to design.



              enter image description here



              Code:



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

              <FrameLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
              <android.support.v7.widget.CardView
              app:cardCornerRadius="4dp"
              app:cardBackgroundColor="@android:color/holo_blue_bright"
              android:layout_width="308dp"
              android:layout_height="112dp"
              android:layout_gravity="right"
              android:layout_margin="10dp">

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

              <TextView
              android:layout_marginStart="40dp"
              android:id="@+id/title"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
              android:paddingLeft="8dp"
              android:text="EARTH"
              android:textColor="#000000"
              android:textSize="70sp" />
              </LinearLayout>

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

              <ImageView
              android:src="@drawable/planet"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_margin="16dp"
              android:elevation="2dp" />
              </FrameLayout>
              </LinearLayout>





              share|improve this answer























              • Thanks, but I changed one line in your code so it could work with my app which was I replaced android:src="@drawable/planet" with android:id="@+id/imageView" and when I run the app it now only displays one card! How would this work with lots of cards?
                – Sixteen
                Nov 9 at 5:30










              • You can very well keep the android:id="@+id/imageView" to have a handle to the image view. My android:src="@drawable/planet" was just a static place holder drawable (the pink circle image) for the image view. These two are entirely different. You can programmatically set the drawable/image resource on the imageView later in your code. This layout is a child layout of your recyclerView. You have to have a adapter for populating your recyclerView with a number of items
                – mukut bhattacharjee
                Nov 9 at 5:52

















              up vote
              1
              down vote



              accepted










              You can use FrameLayout and elevation to fulfill your target.



              According to the documentation of FrameLayout




              Child views are drawn in a stack, with the most recently added child
              on top




              You need to play with the elevation of the ImageView to bring it above the CardView.



              This is what I have achieved: You can then modify your paddings/margins according to design.



              enter image description here



              Code:



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

              <FrameLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
              <android.support.v7.widget.CardView
              app:cardCornerRadius="4dp"
              app:cardBackgroundColor="@android:color/holo_blue_bright"
              android:layout_width="308dp"
              android:layout_height="112dp"
              android:layout_gravity="right"
              android:layout_margin="10dp">

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

              <TextView
              android:layout_marginStart="40dp"
              android:id="@+id/title"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
              android:paddingLeft="8dp"
              android:text="EARTH"
              android:textColor="#000000"
              android:textSize="70sp" />
              </LinearLayout>

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

              <ImageView
              android:src="@drawable/planet"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_margin="16dp"
              android:elevation="2dp" />
              </FrameLayout>
              </LinearLayout>





              share|improve this answer























              • Thanks, but I changed one line in your code so it could work with my app which was I replaced android:src="@drawable/planet" with android:id="@+id/imageView" and when I run the app it now only displays one card! How would this work with lots of cards?
                – Sixteen
                Nov 9 at 5:30










              • You can very well keep the android:id="@+id/imageView" to have a handle to the image view. My android:src="@drawable/planet" was just a static place holder drawable (the pink circle image) for the image view. These two are entirely different. You can programmatically set the drawable/image resource on the imageView later in your code. This layout is a child layout of your recyclerView. You have to have a adapter for populating your recyclerView with a number of items
                – mukut bhattacharjee
                Nov 9 at 5:52















              up vote
              1
              down vote



              accepted







              up vote
              1
              down vote



              accepted






              You can use FrameLayout and elevation to fulfill your target.



              According to the documentation of FrameLayout




              Child views are drawn in a stack, with the most recently added child
              on top




              You need to play with the elevation of the ImageView to bring it above the CardView.



              This is what I have achieved: You can then modify your paddings/margins according to design.



              enter image description here



              Code:



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

              <FrameLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
              <android.support.v7.widget.CardView
              app:cardCornerRadius="4dp"
              app:cardBackgroundColor="@android:color/holo_blue_bright"
              android:layout_width="308dp"
              android:layout_height="112dp"
              android:layout_gravity="right"
              android:layout_margin="10dp">

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

              <TextView
              android:layout_marginStart="40dp"
              android:id="@+id/title"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
              android:paddingLeft="8dp"
              android:text="EARTH"
              android:textColor="#000000"
              android:textSize="70sp" />
              </LinearLayout>

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

              <ImageView
              android:src="@drawable/planet"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_margin="16dp"
              android:elevation="2dp" />
              </FrameLayout>
              </LinearLayout>





              share|improve this answer














              You can use FrameLayout and elevation to fulfill your target.



              According to the documentation of FrameLayout




              Child views are drawn in a stack, with the most recently added child
              on top




              You need to play with the elevation of the ImageView to bring it above the CardView.



              This is what I have achieved: You can then modify your paddings/margins according to design.



              enter image description here



              Code:



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

              <FrameLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
              <android.support.v7.widget.CardView
              app:cardCornerRadius="4dp"
              app:cardBackgroundColor="@android:color/holo_blue_bright"
              android:layout_width="308dp"
              android:layout_height="112dp"
              android:layout_gravity="right"
              android:layout_margin="10dp">

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

              <TextView
              android:layout_marginStart="40dp"
              android:id="@+id/title"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
              android:paddingLeft="8dp"
              android:text="EARTH"
              android:textColor="#000000"
              android:textSize="70sp" />
              </LinearLayout>

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

              <ImageView
              android:src="@drawable/planet"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_margin="16dp"
              android:elevation="2dp" />
              </FrameLayout>
              </LinearLayout>






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 9 at 4:22

























              answered Nov 9 at 4:01









              mukut bhattacharjee

              877




              877












              • Thanks, but I changed one line in your code so it could work with my app which was I replaced android:src="@drawable/planet" with android:id="@+id/imageView" and when I run the app it now only displays one card! How would this work with lots of cards?
                – Sixteen
                Nov 9 at 5:30










              • You can very well keep the android:id="@+id/imageView" to have a handle to the image view. My android:src="@drawable/planet" was just a static place holder drawable (the pink circle image) for the image view. These two are entirely different. You can programmatically set the drawable/image resource on the imageView later in your code. This layout is a child layout of your recyclerView. You have to have a adapter for populating your recyclerView with a number of items
                – mukut bhattacharjee
                Nov 9 at 5:52




















              • Thanks, but I changed one line in your code so it could work with my app which was I replaced android:src="@drawable/planet" with android:id="@+id/imageView" and when I run the app it now only displays one card! How would this work with lots of cards?
                – Sixteen
                Nov 9 at 5:30










              • You can very well keep the android:id="@+id/imageView" to have a handle to the image view. My android:src="@drawable/planet" was just a static place holder drawable (the pink circle image) for the image view. These two are entirely different. You can programmatically set the drawable/image resource on the imageView later in your code. This layout is a child layout of your recyclerView. You have to have a adapter for populating your recyclerView with a number of items
                – mukut bhattacharjee
                Nov 9 at 5:52


















              Thanks, but I changed one line in your code so it could work with my app which was I replaced android:src="@drawable/planet" with android:id="@+id/imageView" and when I run the app it now only displays one card! How would this work with lots of cards?
              – Sixteen
              Nov 9 at 5:30




              Thanks, but I changed one line in your code so it could work with my app which was I replaced android:src="@drawable/planet" with android:id="@+id/imageView" and when I run the app it now only displays one card! How would this work with lots of cards?
              – Sixteen
              Nov 9 at 5:30












              You can very well keep the android:id="@+id/imageView" to have a handle to the image view. My android:src="@drawable/planet" was just a static place holder drawable (the pink circle image) for the image view. These two are entirely different. You can programmatically set the drawable/image resource on the imageView later in your code. This layout is a child layout of your recyclerView. You have to have a adapter for populating your recyclerView with a number of items
              – mukut bhattacharjee
              Nov 9 at 5:52






              You can very well keep the android:id="@+id/imageView" to have a handle to the image view. My android:src="@drawable/planet" was just a static place holder drawable (the pink circle image) for the image view. These two are entirely different. You can programmatically set the drawable/image resource on the imageView later in your code. This layout is a child layout of your recyclerView. You have to have a adapter for populating your recyclerView with a number of items
              – mukut bhattacharjee
              Nov 9 at 5:52














              up vote
              0
              down vote













              Try this layout



              <?xml version="1.0" encoding="utf-8"?>
              <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:card_view="http://schemas.android.com/apk/res-auto"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              android:id="@+id/activity_main"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

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

              <android.support.v7.widget.CardView
              android:id="@+id/first"
              app:cardBackgroundColor="@android:color/white"
              app:cardCornerRadius="@dimen/cardview_default_radius"
              app:cardElevation="4dp"
              android:layout_width="match_parent"
              android:layout_height="80dp"
              android:layout_marginLeft="50dp"
              card_view:cardUseCompatPadding="true">

              <RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginLeft="32dp">

              <TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="TEXT"
              android:textSize="18sp"/>

              </RelativeLayout>

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

              </FrameLayout>

              <ImageView
              android:layout_width="50dp"
              android:layout_height="50dp"
              android:layout_marginLeft="32dp"
              android:background="#000000"
              android:layout_marginTop="15dp"
              android:contentDescription="@null"/>

              </RelativeLayout>


              Result:



              enter image description here






              share|improve this answer

























                up vote
                0
                down vote













                Try this layout



                <?xml version="1.0" encoding="utf-8"?>
                <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:card_view="http://schemas.android.com/apk/res-auto"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/activity_main"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

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

                <android.support.v7.widget.CardView
                android:id="@+id/first"
                app:cardBackgroundColor="@android:color/white"
                app:cardCornerRadius="@dimen/cardview_default_radius"
                app:cardElevation="4dp"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:layout_marginLeft="50dp"
                card_view:cardUseCompatPadding="true">

                <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="32dp">

                <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TEXT"
                android:textSize="18sp"/>

                </RelativeLayout>

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

                </FrameLayout>

                <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_marginLeft="32dp"
                android:background="#000000"
                android:layout_marginTop="15dp"
                android:contentDescription="@null"/>

                </RelativeLayout>


                Result:



                enter image description here






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Try this layout



                  <?xml version="1.0" encoding="utf-8"?>
                  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:card_view="http://schemas.android.com/apk/res-auto"
                  xmlns:app="http://schemas.android.com/apk/res-auto"
                  android:id="@+id/activity_main"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent">

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

                  <android.support.v7.widget.CardView
                  android:id="@+id/first"
                  app:cardBackgroundColor="@android:color/white"
                  app:cardCornerRadius="@dimen/cardview_default_radius"
                  app:cardElevation="4dp"
                  android:layout_width="match_parent"
                  android:layout_height="80dp"
                  android:layout_marginLeft="50dp"
                  card_view:cardUseCompatPadding="true">

                  <RelativeLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="32dp">

                  <TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="TEXT"
                  android:textSize="18sp"/>

                  </RelativeLayout>

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

                  </FrameLayout>

                  <ImageView
                  android:layout_width="50dp"
                  android:layout_height="50dp"
                  android:layout_marginLeft="32dp"
                  android:background="#000000"
                  android:layout_marginTop="15dp"
                  android:contentDescription="@null"/>

                  </RelativeLayout>


                  Result:



                  enter image description here






                  share|improve this answer












                  Try this layout



                  <?xml version="1.0" encoding="utf-8"?>
                  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:card_view="http://schemas.android.com/apk/res-auto"
                  xmlns:app="http://schemas.android.com/apk/res-auto"
                  android:id="@+id/activity_main"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent">

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

                  <android.support.v7.widget.CardView
                  android:id="@+id/first"
                  app:cardBackgroundColor="@android:color/white"
                  app:cardCornerRadius="@dimen/cardview_default_radius"
                  app:cardElevation="4dp"
                  android:layout_width="match_parent"
                  android:layout_height="80dp"
                  android:layout_marginLeft="50dp"
                  card_view:cardUseCompatPadding="true">

                  <RelativeLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="32dp">

                  <TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="TEXT"
                  android:textSize="18sp"/>

                  </RelativeLayout>

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

                  </FrameLayout>

                  <ImageView
                  android:layout_width="50dp"
                  android:layout_height="50dp"
                  android:layout_marginLeft="32dp"
                  android:background="#000000"
                  android:layout_marginTop="15dp"
                  android:contentDescription="@null"/>

                  </RelativeLayout>


                  Result:



                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 9 at 3:43









                  Ayush Khare

                  1,101620




                  1,101620






















                      up vote
                      0
                      down vote













                      You can use ConstraintLayout cool property for doing this easily



                      Xml snippet :



                      <?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:layout_width="match_parent"
                      android:layout_height="100dp"
                      android:layout_margin="10dp"
                      app:cardUseCompatPadding="true">
                      <android.support.v7.widget.CardView
                      android:layout_width="0dp"
                      android:layout_height="0dp"
                      android:layout_marginStart="35dp"
                      app:cardBackgroundColor="@color/cardview_dark_background"
                      app:cardUseCompatPadding="true"
                      app:layout_constraintBottom_toBottomOf="parent"
                      app:layout_constraintEnd_toEndOf="parent"
                      app:layout_constraintStart_toStartOf="parent"
                      app:layout_constraintTop_toTopOf="parent" />
                      <de.hdodenhof.circleimageview.CircleImageView
                      android:layout_width="70dp"
                      android:layout_height="70dp"
                      android:src="@android:drawable/ic_dialog_info"
                      android:translationZ="2dp"
                      app:layout_constraintBottom_toBottomOf="parent"
                      app:layout_constraintEnd_toEndOf="parent"
                      app:layout_constraintHorizontal_bias="0.0"
                      app:layout_constraintStart_toStartOf="parent"
                      app:layout_constraintTop_toTopOf="parent" />


                      </android.support.constraint.ConstraintLayout>


                      Output View : enter image description here






                      share|improve this answer



























                        up vote
                        0
                        down vote













                        You can use ConstraintLayout cool property for doing this easily



                        Xml snippet :



                        <?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:layout_width="match_parent"
                        android:layout_height="100dp"
                        android:layout_margin="10dp"
                        app:cardUseCompatPadding="true">
                        <android.support.v7.widget.CardView
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:layout_marginStart="35dp"
                        app:cardBackgroundColor="@color/cardview_dark_background"
                        app:cardUseCompatPadding="true"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
                        <de.hdodenhof.circleimageview.CircleImageView
                        android:layout_width="70dp"
                        android:layout_height="70dp"
                        android:src="@android:drawable/ic_dialog_info"
                        android:translationZ="2dp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintHorizontal_bias="0.0"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />


                        </android.support.constraint.ConstraintLayout>


                        Output View : enter image description here






                        share|improve this answer

























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          You can use ConstraintLayout cool property for doing this easily



                          Xml snippet :



                          <?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:layout_width="match_parent"
                          android:layout_height="100dp"
                          android:layout_margin="10dp"
                          app:cardUseCompatPadding="true">
                          <android.support.v7.widget.CardView
                          android:layout_width="0dp"
                          android:layout_height="0dp"
                          android:layout_marginStart="35dp"
                          app:cardBackgroundColor="@color/cardview_dark_background"
                          app:cardUseCompatPadding="true"
                          app:layout_constraintBottom_toBottomOf="parent"
                          app:layout_constraintEnd_toEndOf="parent"
                          app:layout_constraintStart_toStartOf="parent"
                          app:layout_constraintTop_toTopOf="parent" />
                          <de.hdodenhof.circleimageview.CircleImageView
                          android:layout_width="70dp"
                          android:layout_height="70dp"
                          android:src="@android:drawable/ic_dialog_info"
                          android:translationZ="2dp"
                          app:layout_constraintBottom_toBottomOf="parent"
                          app:layout_constraintEnd_toEndOf="parent"
                          app:layout_constraintHorizontal_bias="0.0"
                          app:layout_constraintStart_toStartOf="parent"
                          app:layout_constraintTop_toTopOf="parent" />


                          </android.support.constraint.ConstraintLayout>


                          Output View : enter image description here






                          share|improve this answer














                          You can use ConstraintLayout cool property for doing this easily



                          Xml snippet :



                          <?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:layout_width="match_parent"
                          android:layout_height="100dp"
                          android:layout_margin="10dp"
                          app:cardUseCompatPadding="true">
                          <android.support.v7.widget.CardView
                          android:layout_width="0dp"
                          android:layout_height="0dp"
                          android:layout_marginStart="35dp"
                          app:cardBackgroundColor="@color/cardview_dark_background"
                          app:cardUseCompatPadding="true"
                          app:layout_constraintBottom_toBottomOf="parent"
                          app:layout_constraintEnd_toEndOf="parent"
                          app:layout_constraintStart_toStartOf="parent"
                          app:layout_constraintTop_toTopOf="parent" />
                          <de.hdodenhof.circleimageview.CircleImageView
                          android:layout_width="70dp"
                          android:layout_height="70dp"
                          android:src="@android:drawable/ic_dialog_info"
                          android:translationZ="2dp"
                          app:layout_constraintBottom_toBottomOf="parent"
                          app:layout_constraintEnd_toEndOf="parent"
                          app:layout_constraintHorizontal_bias="0.0"
                          app:layout_constraintStart_toStartOf="parent"
                          app:layout_constraintTop_toTopOf="parent" />


                          </android.support.constraint.ConstraintLayout>


                          Output View : enter image description here







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 9 at 4:32

























                          answered Nov 9 at 4:02









                          Aslam Hossin

                          679715




                          679715






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219343%2fhow-to-add-an-imageview-outside-and-to-the-left-of-a-card%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







                              這個網誌中的熱門文章

                              Xamarin.form Move up view when keyboard appear

                              Post-Redirect-Get with Spring WebFlux and Thymeleaf

                              Anylogic : not able to use stopDelay()