How to create round circle for the rectangle edges like StickerView Have.
I don't want to use StickerView, because it does not support EditText like function.
My xml code for Rectangle. I would like to add Corners with round big dots.
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
Below is the mainactivity.xml code where I implement the borders for RotatableAutofitEditText.
<com.agilie.RotatableAutofitEditText xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:autofit="http://schemas.android.com/apk/res-auto"
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="128dp"
android:layout_marginTop="272dp"
android:background="#drawable/borders"
android:gravity="center"
android:hint="#string/hint_add_some_text"
android:text="Type Here"
android:textColor="#android:color/white"
android:textColorHint="#android:color/darker_gray"
autofit:clipBounds="false"
autofit:layout_constraintStart_toStartOf="parent"
autofit:layout_constraintTop_toTopOf="parent"
autofit:maxTextSize="#dimen/autoresize_max_text_size"
autofit:minTextSize="#dimen/autoresize_min_text_size"
autofit:minWidth="#dimen/autoresize_min_width"
autofit:movable="true"
autofit:resizable="true"
autofit:rotatable="true" />
You can customize this template with your colors.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="8dp"
android:end="8dp"
android:start="8dp"
android:top="8dp">
<shape android:shape="rectangle">
<solid android:color="#color/colorPrimary" />
</shape>
</item>
<item android:gravity="start|top">
<shape android:shape="oval">
<size
android:width="16dp"
android:height="16dp" />
<solid android:color="#android:color/black" />
</shape>
</item>
<item android:gravity="end|top">
<shape android:shape="oval">
<size
android:width="16dp"
android:height="16dp" />
<solid android:color="#android:color/black" />
</shape>
</item>
<item android:gravity="start|bottom">
<shape android:shape="oval">
<size
android:width="16dp"
android:height="16dp" />
<solid android:color="#android:color/black" />
</shape>
</item>
<item android:gravity="end|bottom">
<shape android:shape="oval">
<size
android:width="16dp"
android:height="16dp" />
<solid android:color="#android:color/black" />
</shape>
</item>
</layer-list>
A list of Github link for StickerView
https://github.com/nimengbo/StickerView
https://github.com/kencheung4/android-StickerView
https://github.com/uptechteam/MotionViews-Android
https://github.com/wuapnjie/StickerView
https://github.com/sangmingming/StickerView
https://github.com/niravkalola/Android-StickerView
https://github.com/Kaka252/StickerView
https://github.com/yovenny/StickerView
https://github.com/lukehutch/android-multitouch-controller
This handles 3 in 1 facility. On Multi-Touch, you can pan your image, you can scale your image and at the same time you can also rotate your image. And you can add number of stickers as you want.
I want to build this shape with bottom line and text inside it i'm confused little bit how to achieve this i tired
some code but don't get required thing.
so far i have tried this code
shape.xml
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Colored rectangle-->
<item>
<shape android:shape="rectangle">
<size
android:width="100dp"
android:height="40dp" />
<solid android:color="#13a89e" />
</shape>
</item>
<!-- This rectangle for the right side -->
<!-- Their color should be the same as layout's background -->
<item
android:right="-100dp"
android:left="100dp"
android:top="-100dp"
android:bottom="-100dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
</layer-list>
it provide the following result.
i also need yellow line below this shape.
thanks for help.
Here is your XML:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Colored rectangle-->
<item>
<shape android:shape="rectangle">
<padding android:top="35dp"/>
<size android:width="200dp" android:height="40dp" />
<solid android:color="#13a89e" />
</shape>
</item>
<!-- Darker colored line-->
<item>
<shape android:shape="line">
<size android:width="100dp"/>
<stroke android:width="4dp" android:color="#123456" />
</shape>
</item>
<!-- This rectangle for the right side -->
<!-- Their color should be the same as layout's background -->
<item
android:right="-200dp"
android:left="200dp"
android:top="-200dp"
android:bottom="-200dp">
<rotate android:fromDegrees="45">
<shape android:shape="rectangle">
<padding android:top="-35dp"/>
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
<!-- This rectangle for the left side -->
<item
android:right="200dp"
android:left="-200dp"
android:top="-200dp"
android:bottom="-200dp">
<rotate android:fromDegrees="-45">
<shape android:shape="rectangle">
<padding android:top="-35dp"/>
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
And this is what it renders to:
Here is my TextView XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context="io.kalabalik.tilted.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/box"
android:text="Your Text!"
android:textColor="#000000"
android:gravity="center_horizontal|bottom"
android:paddingBottom="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
I highly recommend create custom text view for do that it would be more flexible and under control. You need to create path object and with that object you will define your view corners. And if you want view as text you need to override onDraw(Canvas canvas) function you will call canvas.draw(path, paint) method. If you need not only for text field you should override any view group class but for view groups you should override onDispatchDraw function to do that.
You can create your shape like below example
// you can define all points
Point topLeft = new Point(0,0);
Point topRight = new Point(getWidth(),0); // your view width
//...
//cover your corner points
Path path = new Path();
path.moveTo(topLeft.x, topLeft.y);
path.lineTo(topRight.x, topRight.y);
path.lineTo(bottomRight.x, bottomRight.y);
path.lineTo(shapeBottomRight.x, shapeBottomRight.y);
path.lineTo(shapeTop.x, shapeTop.y);
path.lineTo(shapeBottomLeft.x, shapeBottomLeft.y);
path.lineTo(bottomLeft.x, bottomLeft.y);
path.lineTo(topLeft.x, topLeft.y);
canvas.draw(path, paint);
This post helped me a lot in creating a trapezium view https://arkapp.medium.com/trapezium-view-for-android-584799c7e849
<com.arkapp.trapeziumview.TrapeziumCustomView
android:id="#+id/trapeziumCustomView"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_margin="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeColor="#color/teal_200"
app:edgeRadius="18"
app:slopeLength="88"
app:slopeType="bottomRight" />
With the help of this I was able to create a custom view with one edge as a slope
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="28dp"
android:height="5dp"
android:viewportWidth="800"
android:viewportHeight="304">
<path
android:pathData="M215,41.4c0,0.2 -22.9,58.3 -51,129.1 -28,70.8 -51,129.8 -51,131.1l0,2.4 296.1,-0c281.6,-0 296.1,-0.1 295.6,-1.8 -0.2,-0.9 -11.9,-31 -25.9,-66.7 -14.1,-35.8 -36.9,-94.1 -50.9,-129.8l-25.3,-64.7 -193.8,-0c-106.6,-0 -193.8,0.2 -193.8,0.4z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="50"
android:endY="99"
android:startX="50"
android:startY="1"
android:type="linear">
<item
android:color="#FFFFFF"
android:offset="0.0" />
<item
android:color="#AAA8A8"
android:offset="0.8" />
<item
android:color="#AAA8A8"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
I want to create chat bubble using xml resource but i'm not able to make triangle outside of rectangle with right edge i also tried with 9 patch image but when user enters 1 character still it width is not as wrap content. please help me i also put created code of xml resouce.
<item>
<shape android:shape="rectangle">
<solid android:color="#5EB888"/>
<corners android:radius="30dp"/>
</shape>
</item>
<item
android:bottom="-1000dp"
android:right="200dp"
android:gravity="right"
android:top="190dp">
<rotate
android:fromDegrees="-45">
<shape android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</rotate>
</item>
Check out these libraries
It may help you (Y)
Bubble 1
Bubble 2
Bubble 3
Here is the working drawable custom_shape_chat_box.xml :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Transparent Rectangle -->
<item>
<shape android:shape="rectangle">
<size
android:width="300dp"
android:height="60dp" />
<solid android:color="#android:color/transparent" />
</shape>
</item>
<!-- Colored Rectangle -->
<item
android:right="20dp">
<shape android:shape="rectangle">
<size
android:width="300dp"
android:height="60dp" />
<solid android:color="#5EB888" />
</shape>
</item>
<!-- Bottom-Right Triangle -->
<item
android:left="20dp"
android:right="0dp"
android:top="-10dp"
android:bottom="20dp">
<rotate android:fromDegrees="26">
<shape android:shape="rectangle">
<solid android:color="#5EB888" />
</shape>
</rotate>
</item>
</layer-list>
USE:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="24dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/custom_shape_chat_box">
</LinearLayout>
</LinearLayout>
OUTPUT:
Hope this will help~
I want to make a shape for my view like this one.
Is there any way to do that with xml?
Thanks
Here is your custom drawable custom_shape_down_arrow.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Background -->
<item>
<shape android:shape="rectangle">
<size
android:width="250dp"
android:height="20dp" />
<solid android:color="#cdcdcd" />
</shape>
</item>
<!-- Top-Left Line -->
<item
android:right="150dp"
android:bottom="18.7dp">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</item>
<!-- Top-Right Line -->
<item
android:left="150dp"
android:bottom="18.7dp">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</item>
<!-- Left-Diagonal Line -->
<item
android:right="25dp">
<rotate android:fromDegrees="36">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</rotate>
</item>
<!-- Right-Diagonal Line -->
<item
android:left="27dp">
<rotate android:fromDegrees="322">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</rotate>
</item>
</layer-list>
USE:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="24dp"
android:gravity="center_horizontal">
<!-- Custom shape -->
<LinearLayout
android:id="#+id/layout_custom_shape"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:paddingTop="10dp"
android:background="#cdcdcd">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/custom_shape_down_arrow">
</LinearLayout>
</LinearLayout>
</LinearLayout>
OUTPUT:
Hope this will help~
What I'm trying to do is to have a relativelayout with a gradient on it and a gray bottom border, I'm using the below custom view in my application:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list_item_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/list_item_image"
android:layout_width="match_parent"
android:layout_height="#dimen/SIZE_LIST_ITEM_LARGE"
android:scaleType="centerCrop"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/shape_list_item_gradient" />
<com.rahil.widgets.CustomTextView
android:id="#+id/list_item_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:gravity="bottom"
android:textColor="#color/COLOR_BLACK"/>
</RelativeLayout>
and this is shape_list_item_gradient:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#FFFFFFFF"
android:endColor="#00FFFFFF"
android:angle="90" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle">
<stroke android:width="2dp" android:color="#color/COLOR_GRAY" />
</shape>
</item>
</layer-list>
but the above code applies border to all borders not just bottom border. I added the separate shape xml to the relativelayout but it didn't work which I assume the view with gradient covers it maybe?? I'm quiet lost. thanks for your help.
The android:bottom attribute is actually the "bottom offset in pixels" as noted here about layer-list drawables. There is no explicit way to create a rectangle that is stroked only on one side.
However you can use the same trick that Krylez suggested here: https://stackoverflow.com/a/19239478/1538674
So something like this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#FFFFFFFF"
android:endColor="#00FFFFFF"
android:angle="90" />
</shape>
</item>
<item android:top="-3dp" android:right="-3dp" android:left="-3dp">
<shape>
<solid android:color="#android:color/transparent" />
<stroke android:width="2dp" android:color="#color/COLOR_GRAY" />
</shape>
</item>
</layer-list>