I have a problem that I want to create a list view with rounded corners but I failed to achieve the same. Please suggest me for the right solution.
CustomShape XML:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<stroke android:width="1dp" android:color="#ffbbbbbb" />
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"
/>
</shape>
</item>
<item android:top="1dp" android:left="1dp" android:right="1dp" android:bottom="1dp">
<shape >
<solid android:color="#ffffffff" />
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"
/>
</shape>
</item>
</layer-list>
main XML:
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginLeft="10dp" android:layout_marginRight="10dp"
android:layout_marginBottom="10dp" android:layout_marginTop="120dip">
<ListView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/lv_homeScreen" android:cacheColorHint="#color/WHITE" android:dividerHeight="0dp" android:background="#drawable/customshape">
</ListView>
</LinearLayout>
I have attached the code which I am using for the same desire. Please have a look and share me if there are any flaws.
Thanks in advance.
set this container.xml (in drawable) as the background of your listview:
<gradient
android:startColor="#FFF"
android:centerColor="#FFF"
android:endColor="#FFFF"
android:angle="270"/>
<stroke
android:width="2dp"
android:color="#e98d59"/>
<corners
android:radius="10dp"/>
Related
How can i achieve this type of vertical progress bar?The progress bar's progress also has round corner
I tried to find solution but can not find any.I tried to set a custom drawable as follow`
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<gradient
android:angle="180"
android:centerColor="#ffffffff"
android:centerY="0.75"
android:endColor="#ffffffff"
android:startColor="#ffffffff" />
<corners android:radius="#dimen/xxs" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip
android:clipOrientation="vertical"
android:gravity="bottom">
<shape>
<gradient
android:centerColor="#E9E9E9"
android:centerY="0.75"
android:endColor="#E9E9E9"
android:startColor="#E9E9E9" />
<corners android:radius="#dimen/xxs" />
</shape>
</clip>
</item>
</layer-list>
I think you need to go with the some chart library that would be great solution but if you want to go with customisation your chart then go with below code.
veritcal_progressbar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<corners android:radius="5dip"/>
<solid android:color="#FFFFFF"/>
<stroke
android:width="1dp"
android:color="#FF000000" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip
android:clipOrientation="vertical"
android:gravity="bottom">
<shape>
<corners android:radius="5dip"/>
<solid android:color="#FFBE00"/>
<stroke
android:width="1dp"
android:color="#FF000000" />
</shape>
</clip>
</item>
</layer-list>
Use in layout file.
<ProgressBar
android:id="#+id/vprogressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:progressDrawable="#drawable/veritcal_progressbar"/>
You can achieve this using below code
<RelativeLayout 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:gravity="center"
tools:context=".MainActivity">
<com.google.android.material.slider.Slider
android:id="#+id/slider"
android:layout_width="300dp"
android:layout_height="50dp"
android:valueFrom="0.0"
android:valueTo="100.0"
android:value="60.0"
android:rotation="270"
android:scaleY="15"
app:thumbRadius="0dp"
app:haloRadius="0dp"
android:layout_centerInParent="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#color/white"
android:textSize="16dp"
android:text="60%"/>
</RelativeLayout>
Output
I am trying to achieve following layout :
I want to expand each view on click.
How do I obtain the shadow over each view?
I have tried the following drawable :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#cacaca"
android:centerColor="#b6b6b6"
android:endColor="#e9e9e9"
/>
</shape>
<gradient
android:startColor="#6586F0"
android:centerColor="#D6D6D6"
android:endColor="#4B6CD6"
android:angle="90"/>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="5dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
<corners android:radius="20dp"/>
</shape>
</item>
</layer-list>
But it is showing following view :
Please help me to achieve the proper view.
you can achieve this by nesting multiple cardViews inside the FrameLayout.
Change the android:layout_marginTop and app:cardElevation properties to give this stack effect.
Try below code :
For Drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Drop Shadow Stack -->
<item>
<shape android:shape="rectangle">
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<solid android:color="#14000029" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<solid android:color="#14000029" />
</shape>
</item>
<item>
<shape
android:shape="rectangle">
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<solid android:color="#14000029" />
</shape>
</item>
<!-- Background -->
<item>
<shape
android:shape="rectangle">
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<solid android:color="#android:color/white"/>
</shape>
</item>
</layer-list>
Code in Layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".CardViewShadowActivity"
android:layout_marginTop="30dp">
<LinearLayout
android:id="#+id/linear_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="30dp"
android:background="#drawable/custom_bg">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="30dp"
android:background="#drawable/custom_bg"
android:layout_below="#id/linear_1"
android:layout_marginTop="-20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="30dp"
android:background="#drawable/custom_bg"
android:layout_below="#id/linear_2"
android:layout_marginTop="-20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="30dp"
android:background="#drawable/custom_bg"
android:layout_below="#id/linear_3"
android:layout_marginTop="-20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</LinearLayout>
</RelativeLayout>
Customize layout and drawable according to your need.
Output for above code is:
I hope this helps you
how can make this shape in android studio with xml?
a semi-circle on top of rectangle.
i want to put profile picture in top and text inside the rectangle.
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff"/>
<stroke android:width="1dp" android:color="#201215cc" />
<corners android:radius="8dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="100dp"
android:height="40dp"
android:bottom="4dp"
android:top="10dp">
<shape>
<solid android:color="#000" />
<corners android:radius="2dp"/>
</shape>
</item>
<item
android:width="20dp"
android:height="10dp"
android:left="10dp"
android:top="1dp">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#000000"/>
<corners
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
</shape>
</item>
<item
android:width="98dp"
android:height="38dp"
android:bottom="5dp"
android:top="11dp"
android:start="1dp">
<shape>
<solid android:color="#fff" />
<corners android:radius="2dp"/>
</shape>
</item>
<item
android:width="18dp"
android:height="10dp"
android:left="11dp"
android:top="2dp">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fff"/>
<corners
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
</shape>
</item>
</layer-list>
Output like
It can be done using ConstraintLayout.
Alight your profile pic in vertical center of top border of your rectangle and apply some start(left) margin to it.
<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">
<LinearLayout
android:id="#+id/your_rectangle"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginStart="20dp"
android:layout_marginTop="80dp"
android:layout_marginEnd="20dp"
android:background="#c6c6c6"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="#+id/your_view"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginStart="20dp"
android:background="#451245"
app:layout_constraintBottom_toTopOf="#id/your_rectangle"
app:layout_constraintStart_toStartOf="#id/your_rectangle"
app:layout_constraintTop_toTopOf="#id/your_rectangle" />
</androidx.constraintlayout.widget.ConstraintLayout>
I'm trying to set a transparent circle with a stroke as the background of a TextView in android:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:background="#drawable/decibel_circle"
android:text="30 dB"
android:fontFamily="sans-serif"
android:textColor="#android:color/black"
android:textSize="70dp" />
</RelativeLayout>
And this is the shape I want to use, located in decibel-circle.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="5dp"
android:color="#F44336">
</stroke>
<solid android:color="#android:color/transparent"/>
<size
android:width="36dp"
android:height="36dp" />
<corners android:radius="12dp" />
</shape>
</selector>
The problem is that the shape is never shown, neither in the preview nor when I run my app.
What am I doing wrong?
in your decibel-circle.xml remove selector just use shape alone
Use this only
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="5dp"
android:color="#F44336">
</stroke>
<solid android:color="#android:color/transparent"/>
<size
android:width="36dp"
android:height="36dp" />
<corners android:radius="12dp" />
</shape>
The following is my ListView with a background. List items when pressed are showing unwanted areas at upper right and lower right corners. I want them to disappear. What can I do?
I have attached the XML code for the background here:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="15dp">
<shape android:shape="rectangle" >
<solid android:color="#6bb726" />
<size android:width="3dp" android:height="0dp" />
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle" >
<solid android:color="#aaaaaa" />
<corners
android:bottomLeftRadius="0.1dp"
android:bottomRightRadius="15dp"
android:topLeftRadius="0.1dp"
android:topRightRadius="15dp" />
</shape>
</item>
<item android:left="5dp" android:top="2dp" android:bottom="2dp" android:right="2dp">
<shape android:shape="rectangle">
<gradient
android:type="radial"
android:centerX="150%"
android:centerY="50%"
android:startColor="#999999"
android:endColor="#eeeeee"
android:gradientRadius="100"/>
<corners
android:bottomLeftRadius="0.1dp"
android:bottomRightRadius="12dp"
android:topLeftRadius="0.1dp"
android:topRightRadius="12dp" />
</shape>
</item>
</layer-list>
ListView layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/denko_station_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="50dp"
android:divider="#android:color/transparent"
android:dividerHeight="10dp" />
</RelativeLayout>
just add the following line in listview layout code:
android:listSelector="#android:color/transparent"
like below
<ListView
android:id="#+id/lvId"
android:layout_width="match_parent"
android:listSelector="#android:color/transparent"
android:layout_height="match_parent"/>
Set
android:listSelector="#android:color/transparent"
for your listView in xml file.