Issue
Solution
There ae many ways of above design , I don't know its a good way but it will work as per requirement
Here I create two drawable one for button radius shape and second one is dimond shape, Now you will manage visibility of diamond shape view as per your requirement for example if button click visible/gone diamond shape.
button_round_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#545454" />
<corners
android:radius="15dp" />
</shape>
dimond_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp">
<rotate android:fromDegrees="45">
<shape>
<size
android:width="5dp"
android:height="5dp" />
<gradient
android:startColor="#4cd964"
android:endColor="#4cd964" />
</shape>
</rotate>
</item>
</layer-list>
xml layout code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:id="@+id/btn"
android:background="@drawable/button_round_shape"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn_shape"
android:layout_width="10dp"
android:visibility="gone"
android:layout_toRightOf="@+id/btn"
android:background="@drawable/dimond_shape"
android:layout_marginLeft="-25dp"
android:layout_marginTop="7dp"
android:layout_height="10dp" />
</RelativeLayout>
</RelativeLayout>
JAVA code
btn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
// PRESSED
btn_shape.setVisibility(View.VISIBLE);
return true; // if you want to handle the touch event
case MotionEvent.ACTION_UP:
// RELEASED
btn_shape.setVisibility(View.GONE);
return true; // if you want to handle the touch event
}
return false;
}
});
Answered By - Adil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.