Reputation: 21
How can I make the Linear layout's background transparent?
I want to make the area around the share button transparent. I have tried various solutions like
android:background="@android:color/transparent"
and
android:alpha="0"
and many other solutions but none of these seems working. How can I make this area transparent over the image and other elements? I have also tried the Frame Layout but it also doesn't work.
Here is my XML code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent"
android:theme="@style/Theme.MaterialComponents"
tools:context=".ReadMoreActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="100dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/readMoreImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/readMoreTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Card Title"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="30dp" />
<TextView
android:id="@+id/readMoreDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:paddingBottom="20dp"
android:text="Card description"
android:textAlignment="textStart"
android:textColor="#000000" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="-100dp"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:id="@+id/shareButton"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:text="Share"
android:textColor="#ffff"
android:textSize="25dp"
app:backgroundTint="#9C27B0"
app:strokeColor="#9C27B0"
app:strokeWidth="2dp" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 1
Views: 121
Reputation: 9852
If I undestood You correclty You can do it like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"
android:theme="@style/Theme.MaterialComponents"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher_background"
/>
<TextView
android:id="@+id/readMoreTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Card Title"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="30sp"
/>
<TextView
android:id="@+id/readMoreDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="@string/long_card_desc"
android:textAlignment="textStart"
android:textColor="#000000"
>
</TextView>
</LinearLayout>
</ScrollView>
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:backgroundTint="#880E4F"
android:text="Share"
android:textColor="#FFF9C4"
app:cornerRadius="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:strokeColor="#006064"
app:strokeWidth="1dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Now Button sticks to the bottom of the screen and You can scroll the content.
Result (left with a scrolled view and right starter look):
Upvotes: 1