I am trying to make a imageview Rounded corners
I am trying to set it through XML and not programatically !
I have set background for my reference
Is it not possible to to set round corners through xml & we have to use bitmap ?
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round_cornered_imageview"
android:src="#drawable/image" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My-Text"
android:textColor="#color/textbody"
android:layout_gravity="bottom|center"
android:textSize="40sp" />
<Button
android:id="#+id/button1"
android:layout_width="108dp"
android:layout_height="74dp"
android:background="#color/textbody"
android:layout_gravity="top|center"
android:text="Button" />
</FrameLayout>
</LinearLayout>
OUTPUT
What i have tried ::
rounded_cornered_imageview.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
<stroke
android:color="#color/black"
android:width="1dp"
/>
</shape>
But its not working ... where i need to correct myself ?
you can follow this below:
on your gradle in dependencies
implementation 'com.makeramen:roundedimageview:2.3.0'
on your xml file
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/img_home_assistance"
android:layout_width="match_parent"
android:layout_height="123dp"
app:riv_corner_radius="#dimen/padding_margin_15"
android:layout_marginTop="6.8dp"
android:layout_marginLeft="7.3dp"
android:layout_marginRight="7.5dp"
android:src="#drawable/migrate"
android:scaleType="centerCrop"/>
Related
https://drive.google.com/open?id=1yOkIr0uu6iqwjin2_H00K7gkP_f7g1_r
please help me how to create that kinda button with red color shadow
You just have to use CardView for this kind shadow background
add below library
implementation 'com.android.support:design:26.1.0' //support design
compile 'com.android.support:cardview-v7:26.1.0' // CardView
in your xml layout declare cardview
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
card_view:cardBackgroundColor="#C8242A"
card_view:cardCornerRadius="15dp"
card_view:cardElevation="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="#style/TextAppearance.AppCompat.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:paddingTop="5dp"
android:text="Sign in"
android:textColor="#fff" />
</LinearLayout>
</android.support.v7.widget.CardView>
Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:gravity="center"
tools:context=".activity.SplashActivity">
<Button
android:layout_width="match_parent"
android:background="#drawable/aa"
android:layout_height="wrap_content" />
</LinearLayout>
android:background="#drawable/aa"
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/shadow_bg" >
</item>
<item>
<shape android:shape="rectangle" android:padding="10dp">
<corners android:radius="40dp" />
<gradient
android:angle="45"
android:endColor="#3cff00"
android:startColor="#ff00ff"
android:type="linear" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>
</item>
</layer-list>
android:drawable="#drawable/shadow_bg"
OUTPUT
NOTE: You can use Android 9-patch shadow generator to create 9-patch image as per requirement
I'm trying to use Android Elevation to achieve the 'shadow' look for a view. The following is the layout xml:
<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="com.sample.app.Main2Activity">
<LinearLayout
android:layout_width="395dp"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:clipChildren="false">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="165dp"
android:background="#FFFFFF"
android:padding="30dp"
android:layout_margin="30dp"
android:elevation="10dp"
android:text="TextView" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
This is how the layout looks:
Look ma, no shadows!
Any suggestions to fix this?
Here you go.... maybe you need someone to do it for you then....
I used a card view instead...
xml layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_margin="5dp"
card_view:cardCornerRadius="5dp"
card_view:contentPadding="10dp">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textView"
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView2"
android:text="world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:layout_marginTop="10dp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Add these to your app gradle file
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
result:
and if you dont want to use a card view.....
xml -> layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/border"
android:layout_margin="5dp"
android:padding="5dp">
<TextView
android:id="#+id/textView"
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView2"
android:text="world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:layout_marginTop="10dp"/>
</RelativeLayout>
</LinearLayout>
#drawable/border
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Drop Shadow Stack -->
<item>
<shape>
<gradient
android:centerColor="#D5E2ED"
android:endColor="#0000"
android:angle="90"/>
</shape>
</item>
<item android:bottom="10dp">
<shape>
<solid android:color="#D5E2ED"/>
</shape>
</item>
<!-- base background -->
<item android:bottom="5dp" android:top="1dp">
<shape android:shape="rectangle">
<solid android:color="#fff"/>
<padding android:bottom="10dp" android:top="10dp"/>
</shape>
</item>
</layer-list>
result:
happy coding....
I'll get to the answer, but some background first. I was trying to achieve the look with a custom view that used a ConstraintLayout. This view would be used in another layout. I was when I tried using a simple TextView that I realised that the shadows weren't being rendered because, thus destroying my assumption that it was something ConstraintLayout related.
What worked?
I know, from the documentations, that shadows and rendered using a View's background. This, I have, and indeed, it was a solid color with no alpha value (as others on SO have mentioned).
Much like so:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
It was after I added android:radius to this, and then the shadows were rendered.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffff" />
<corners android:radius="1dp" />
</shape>
And if you were wondering, why not set it to 0dp? Well, the shadows disappear again when the radius values were set to 0dp.
How to draw button like below image in xml? Basically, it has two different buttons. One is for I. another one is for Pick Up. Thanks.
Try this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/bg_btn_coner"
android:gravity="center"
android:text="Pickup"
android:textColor="#android:color/white"
android:textSize="20sp" />
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/bg_btn_coner"
android:gravity="center"
android:text="i"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
and bg_btn_coner.xml
<solid android:color="#737373" />
<stroke
android:width="3dp"
android:color="#android:color/white"></stroke>
<corners android:radius="50dp"></corners>
Result:
Try this. Example image is shown.
Note: you will have to fix the path to make the image perfect.
button_circle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#android:color/darker_gray" />
</shape>
button_rectangle.xml
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="720dp"
android:height="576dp"
android:viewportWidth="720"
android:viewportHeight="576">
<path
android:fillColor="#android:color/darker_gray"
android:pathData="M700.461,426.359c0,51.164-7.764,92.641-17.336,92.641H76.369
c-9.575,0,17.191-101.692,17.191-152.855l-1.444-173.699c0-51.164-25.321-136.646-15.747-136.646h606.756
c9.572,0,17.336,41.476,17.336,92.64V426.359z" />
</vector>
You will have to fix the vector to make the shape perfect. but this a good example for u.
my_layout.xml:
<?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">
<Button
android:layout_width="match_parent"
android:layout_height="42dp"
android:background="#drawable/button_rectangle"/>
<Button
android:layout_width="42dp"
android:layout_height="42dp"
android:background="#drawable/button_circle"/>
</RelativeLayout>
Hope this helps!
I have a ImageView and I want to set a rounded border, I have it with a drawable shape but at the right and bottom, the border its not correct, I set a screenshot for understand this:
This is the XML code:
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/et_message"
android:layout_toRightOf="#+id/rl_bt_s"
android:layout_toEndOf="#+id/rl_bt_s"
android:layout_toStartOf="#+id/send_bt_c"
android:layout_toLeftOf="#+id/send_bt_c"
android:layout_centerVertical="true"
android:layout_height="wrap_content"/>
<RelativeLayout
android:id="#+id/rl_bt_s"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/et_message"
android:padding="6dp"
android:gravity="center">
<ImageButton
android:id="#+id/bt_chat_s"
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="10dp"
android:background="#android:color/transparent"
android:clickable="false"/>
<ImageView
android:id="#+id/iv_action_attach"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignLeft="#id/bt_chat_s"
android:layout_alignStart="#id/bt_chat_s"
android:src="#drawable/icon_input_plus"
android:background="#drawable/chat_attachment_border_smsmode"/>
</RelativeLayout>
</merge>
And this is the shape:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<stroke android:width="1dp"
android:color="#999999"
/>
<padding android:left="4dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp"
/>
<corners android:radius="4dp"/>
</shape>
As you can see in the screenshot, the right border and bottom border its not completely but I don't know why.
Try changing the parent RelativeLayout to have the width you desire and have the child views match_parent for their width/height.
<RelativeLayout
android:id="#+id/rl_bt_s"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignBottom="#id/et_message"
android:gravity="center">
<ImageButton
android:id="#+id/bt_chat_s"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:background="#android:color/transparent"
android:clickable="false"/>
<ImageView
android:id="#+id/iv_action_attach"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/icon_input_plus"
android:background="#drawable/chat_attachment_border_smsmode"/>
</RelativeLayout>
I am trying to add a top border to a LinearLayout with a transparent background.
The result should be like the following image, where the border is the top border of the "Jp Project" LinearLayout. The background color comes from a FrameLayout who is used as container.
This is the linear layout XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menuItem"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/icon"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="#drawable/notification_action"
android:padding="10dp"/>
<TextView
android:id="#+id/menuItemName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="19sp"
android:textColor="#color/white"/>
<TextView android:id="#+id/counter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:textAppearance="#android:style/TextAppearance.Medium"
android:textColor="#color/counter_text_color"
android:background="#drawable/counter_bg"/>
</LinearLayout>
This is the style code I am using at the moment:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="2dp"
android:color="#color/base_app_color" />
<solid android:color="#android:color/transparent"/>
</shape>
Which draws:
Have you got any way to fix it just using styles?
Set as your LinearLayout background the drawable with this code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="-2dp" android:bottom="-2dp" android:right="-2dp">
<shape android:shape="rectangle">
<stroke android:width="2dp" android:color="#color/borderColor" />
<solid android:color="#color/backgroundColor" />
</shape>
</item>
</layer-list>
As the line should be middle aligned vertically between the Workplaces and Project menu items. I am identifying the Project item as an especial menu item and applying a different layout.
The layout code is:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:background="#drawable/project_top_line">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/icon"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="#drawable/notification_action"
android:padding="10dp"/>
<TextView
android:id="#+id/menuItemName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="19sp"
android:textColor="#color/white"/>
<TextView android:id="#+id/counter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:textAppearance="#android:style/TextAppearance.Medium"
android:textColor="#color/counter_text_color"
android:background="#drawable/counter_bg"/>
</LinearLayout>
</LinearLayout>
The style code is:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="2dp"
android:color="#color/base_app_color" />
<solid android:color="#android:color/transparent"/>
</shape>
which draws a line in the middle of the first linear layout.
I think you only need a blue line so you can do something like this:
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/holo_blue_dark" />
Make a file called border.xml and add this to your layout for making only top border.
<item
android:left="-1dp"
android:right="-1dp"
android:bottom="-1dp"
android:top="1dp">
<shape
android:shape="rectangle">
<stroke
android:width="0.5dp"
android:color="#color/black" />
<solid android:color="#android:color/transparent" />
</shape>
</item>
like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/kellton_logo"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/border"
>
Helped for me.