Reputation: 37
I've got an app I'm working on that I inherited. I'm trying to make it so the box in the image provided below labeled "RelativeLayout" stretches all the way to edge of the screen horizontally, so that there's no white space in between it and the screen. Any way to do that? I've tried "match_parent" and "wrap_content" but neither of those do the trick
<?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="wrap_content"
android:orientation="vertical"
android:id="@+id/view_cont"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="1dp"
android:elevation="1dp"
card_view:cardCornerRadius="15dp"
card_view:cardElevation="1dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#406490">
<TextView
android:id="@+id/leg_name"
android:layout_width="207dp"
android:layout_height="44dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="12dp"
android:layout_marginEnd="9dp"
android:layout_marginRight="9dp"
android:fontFamily="sans-serif-thin"
android:gravity="right"
android:text="Name"
android:textColor="@color/colorPrimary"
android:textSize="18sp" />
<TextView
android:id="@+id/leg_office"
android:layout_width="207dp"
android:layout_height="64dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="64dp"
android:layout_marginEnd="9dp"
android:layout_marginRight="9dp"
android:fontFamily="sans-serif-thin"
android:gravity="right"
android:text="President of the United States Amercia"
android:textColor="@color/colorPrimary" />
<ImageView
android:id="@+id/leg_photo"
android:layout_width="127dp"
android:layout_height="121dp"
android:layout_below="@+id/leg_name"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="-47dp"
card_view:srcCompat="@drawable/icon1" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Upvotes: 0
Views: 195
Reputation: 1500
this is happening because you added a margin of 1dp to your parent CardView. Also because card_view:cardUseCompatPadding
is set to TRUE
Try the following 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="wrap_content"
android:orientation="vertical"
android:id="@+id/view_cont"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:elevation="1dp"
card_view:cardCornerRadius="15dp"
card_view:cardElevation="1dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#406490">
<TextView
android:id="@+id/leg_name"
android:layout_width="207dp"
android:layout_height="44dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="12dp"
android:layout_marginEnd="9dp"
android:layout_marginRight="9dp"
android:fontFamily="sans-serif-thin"
android:gravity="right"
android:text="Name"
android:textColor="@color/colorPrimary"
android:textSize="18sp" />
<TextView
android:id="@+id/leg_office"
android:layout_width="207dp"
android:layout_height="64dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="64dp"
android:layout_marginEnd="9dp"
android:layout_marginRight="9dp"
android:fontFamily="sans-serif-thin"
android:gravity="right"
android:text="President of the United States Amercia"
android:textColor="@color/colorPrimary" />
<ImageView
android:id="@+id/leg_photo"
android:layout_width="127dp"
android:layout_height="121dp"
android:layout_below="@+id/leg_name"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="-47dp"
card_view:srcCompat="@drawable/ic_directions_walk_black_24dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Hope this works, good luck!
Upvotes: 1