Android - drawable with rounded corners at the top only
Try giving these values:
<corners android:topLeftRadius="6dp" android:topRightRadius="6dp"
android:bottomLeftRadius="0.1dp" android:bottomRightRadius="0.1dp"/>
Note that I have changed 0dp
to 0.1dp
.
EDIT: See Aleks G comment below for a cleaner version
how to round only top two corners in my case
Try this
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke
android:width="3dp"
android:color="#B1BCBE" />
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp"
android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/>
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>
OUTPUT
Android: how to clip only top rounded corners
I've managed to get this working by creating a custom ViewOutlineProvider and using that instead of a background value
ViewOutlineProvider mViewOutlineProvider = new ViewOutlineProvider() {
@Override
public void getOutline(final View view, final Outline outline) {
float cornerRadiusDP = 16f;
float cornerRadius = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, cornerRadiusDP, getResources().getDisplayMetrics());
outline.setRoundRect(0, 0, view.getWidth(), (int)(view.getHeight() + cornerRadius), cornerRadius);
}
};
scrollView.setOutlineProvider(mViewOutlineProvider);
scrollView.setClipToOutline(true);
ImageView with only bottom or top corners rounded
Here is the another way to do this using Material Design ShapeableImageView
Create one theme for shape and cornerFamily
<style name="ImageView.Corner" parent="">
<item name="cornerSizeTopRight">8dp</item>
<item name="cornerSizeTopLeft">8dp</item>
<item name="cornerSizeBottomLeft">0dp</item>
<item name="cornerSizeBottomRight">0dp</item>
<item name="cornerFamily">rounded</item>
</style>
Now add ShapeableImageView in XML:
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="75dp"
android:layout_height="75dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/temp_product_image"
app:shapeAppearanceOverlay="@style/ImageView.Corner"/>
I you want to full rounded ShapeableImageView:
<style name="ImageView.Round" parent="">
<item name="cornerSize">50%</item>
</style>
Full Rounded Output:
That's it Happy Coding :).
How to create a layout with rounded corners on only the top or bottom half?
You can achieve this using material cardview. Here's the xml code of the full layout file:
<?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">
<com.google.android.material.card.MaterialCardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="10dp"
app:cardCornerRadius="30dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#406cca"
android:visibility="visible" />
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#fb7500" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
Remember, if the image is not there, just make the visibility of that particular imageview in your recyclerview to View.GONE in your code.
I hope you understood. If any queries, put a comment!
Here a pic of what this code looks like:
Related Topics
Android Firebase Dynamitemodule: Failed to Load Module Descriptor
How to Create a Transparent Demo Screen for an Android App
Android - How to Download a File from a Webserver
Changing Background Color of Selected Item in Recyclerview
How to Create a Circular (Endless) Recyclerview
"An Internal Error Occurred" with Integration of Google Plus Login
How to Create Spinner-List Using Customadapter in Android
Background-Size:Cover Not Working in Android Native Browser
Disabling of Edittext in Android
How to Retrieve the Android Sdk Version
Android: How to Convert String to Date
Passing Data of a Non-Primitive Type Between Activities in Android
Passing Data from One Activity to Another Using Bundle - Not Displaying in Second Activity
Recyclerview - How to Smooth Scroll to Top of Item on a Certain Position