I am using a floating action button (without using third part library)
The fab appears fine on mdpi and hdpi devices but appears as a distinctive oval shape on ldpi devices
For reference here are the screenshots -
- Here is the fab rendering fine on mdpi devices
- Here is the fab rendering as an oval on ldpi devices
The main layout has an include element to include the fab layout . The fab layout includes a background as a drawable . background=@drawable/fab_drawable
A. fab_drawable.xml in res/drawable
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="8px">
<layer-list>
<item>
<shape android:shape="oval">
<solid android:color="#14000000"/>
<padding
android:bottom="1px"
android:left="0px"
android:right="1px"
android:top="1px"
/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#15000000"/>
<padding
android:bottom="1px"
android:left="0px"
android:right="1px"
android:top="1px"
/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#16000000"/>
<padding
android:bottom="1px"
android:left="0px"
android:right="1px"
android:top="1px"
/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#17000000"/>
<padding
android:bottom="1px"
android:left="0px"
android:right="1px"
android:top="1px"
/>
</shape>
</item>
</layer-list>
</item>
<item android:id="@+id/fab_drawable_shape">
<shape android:shape="oval" >
<solid android:color="#404952" />
</shape>
</item>
<item android:drawable="@drawable/onboarding_selector"/>
B. fab_drawable.xml in drawable-v21
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight" >
<item>
<shape android:shape="oval" >
<solid android:color="?android:colorAccent" />
</shape>
</item>
C. In my basefragment i am checking if build is lollipop then use this clipping code
ViewOutlineProvider fabOutlineProvider = new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
int diameter = getResources().getDimensionPixelSize(
R.dimen.fab_diameter);
outline.setOval(0, 0, diameter, diameter);
}
};
mComposeFabButtonView.setOutlineProvider(fabOutlineProvider);
mComposeFabButtonView.setClipToOutline(true);
D. The dimensions of the fab button diameter are 60sp for all devices