Reputation: 456
I have a Relative Layout with some views like ImageView, TextView etc inside it. There are also unused spaces. I only want the unused spaces to be transparent, not the Views. But whatever I do like set alpha, it makes the whole thing inside the Relative Layout change. Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
app:cardElevation="0dp"
android:layout_gravity="bottom"
android:gravity="bottom"
android:background="@android:color/transparent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom"
android:gravity="bottom"
android:background="@android:color/transparent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:id="@+id/rl"
android:layout_gravity="bottom"
android:gravity="bottom"
android:background="@android:color/transparent"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profilepicBlog"
android:layout_width="54dp"
android:layout_height="54dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="1dp"
android:layout_marginStart="12dp"
android:layout_marginTop="9dp"
android:padding="6dp"
android:src="@drawable/defimg"
app:civ_border_color="#2a30a3"
app:civ_border_width="1dp"
/>
<TextView
android:id="@+id/post_username"
android:layout_width="193dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="74dp"
android:paddingLeft="14dp"
android:text="UserName"
android:textSize="16sp"
android:textStyle="bold|italic"
android:textColor="#4d5459"
android:layout_marginTop="16dp"
/>
<ImageButton
android:id="@+id/tools"
android:layout_width="37dp"
android:layout_height="34dp"
style="?android:attr/borderlessButtonStyle"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="14dp"
android:rotation="90"
android:src="@drawable/icon_image"
/>
<TextView
android:id="@+id/usertime"
android:layout_width="193dp"
android:layout_height="20dp"
android:layout_alignStart="@+id/post_username"
android:layout_below="@+id/post_username"
android:paddingLeft="14dp"
android:text="TextView"
android:textStyle="bold"
android:textColor="#737377"
/>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
As you can see, there is a cardview, inside which there is a linear layout, inside which there is the relative layout. The relative layout contains different views. I want to make the unused parts in relative layout transparent so that when the cardview is retrieved in recyclerview in an activity, only the views are visible.
Upvotes: 0
Views: 1692
Reputation: 387
Just add this to your CardView's layout: card_view:cardBackgroundColor="@android:color/transparent"
You don't need to set the other background layouts to transparent.
Upvotes: 3