Rounding the corners of views in notepad android app - android

I currently have this user interface on my app.
I would like to round the edges of the notes like I managed to do in the composing section of the app, as below
I was able to do this by using the following in a file in drawable called timetable_item_border.xml,
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="0dp"
android:color="#000" />
<solid android:color="#color/tile_background" />
<padding
android:bottom="#dimen/tile_padding"
android:left="#dimen/tile_padding"
android:right="#dimen/tile_padding"
android:top="#dimen/tile_padding" />
<!-- <corners android:radius="1dp" /> -->
<corners android:radius="10dp"/>
</shape>
I tried to apply android:background:#drawable/timetable_item_border at the start of the following file but it curved the corners of the notes but removed all the padding, which I didnt want. (I put it at the start of the frame layout but before the linear layout).
This is file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/note_tile_margin">
<LinearLayout
android:id="#+id/tile_clickable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#drawable/tile_selector"
android:clickable="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/noteTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="#dimen/tile_padding"
android:layout_toLeftOf="#+id/btn_tile_expand"
android:ellipsize="end"
android:maxLines="#integer/max_tile_lines"
android:singleLine="false"
android:text="Write your message here... "
android:textColor="#color/tile_text" />
<LinearLayout
android:id="#+id/btn_tile_expand"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/click_selector"
android:gravity="top" >
<ImageView
android:id="#+id/btn_tile_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="7dp"
android:src="#drawable/icon_dark_expand" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/tile_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:visibility="gone" >
<ImageView
android:id="#+id/btn_tile_links"
style="#style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="Hyperlinks"
android:src="#drawable/icon_dark_web" />
<ImageView
android:id="#+id/btn_tile_delete"
style="#style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="#string/deleteNote"
android:src="#drawable/icon_dark_delete" />
<ImageView
android:id="#+id/btn_tile_share"
style="#style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="#string/share"
android:src="#drawable/icon_dark_share" />
<ImageView
android:id="#+id/btn_tile_copy"
style="#style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="Copy to clipboard"
android:src="#drawable/icon_dark_copy" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
How should I curve the notes? What am I not seeing correctly?
Note: The original source code comes from here, https://github.com/mick88/notepad, I am just redoing the graphics.

Google have created a view for this very case. The CardView http://developer.android.com/training/material/lists-cards.html

If you use cardview try this
card_view:cardCornerRadius=""

Related

Custom EditText into Android

I'd like to put attach file icon into EditText for example how it was made into WhatsApp. How can I do it?
That is not a custom EditBox. Here EditText is wrapped with parent view with other ImageViews.
In whatsapp example there is a Imogi ImageView, An EditText, An Attach ImageView, and a camera ImageView inside a LinearLayout. And parent LinearLayout is having round corner background.
You can also use Drawable left and Drawable right, but I will not suggest that because that does not have much control.
Just a suggestion:
I always want to save time. Here is an whatsapp clone, you can just pull it and use its views.
https://github.com/Shahar2k5/whatsappClone
This guy has done good work in this library.
Use drawableRight attribute in EditText
<EditText
android:id="#+id/account_et"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:drawableRight="#drawable/icon_backall" //your drawable which you want to use
android:ems="10"
android:hint="#string/str_md_email"
android:padding="10dp" >
</EditText>
You have to manage like below image :
For above UI design code is below :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="#dimen/_10sdp"
android:background="#drawable/stockbg"
android:orientation="horizontal">
<EditText
android:id="#+id/edt_sendMeassage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_10sdp"
android:layout_marginRight="#dimen/_10sdp"
android:layout_weight="1"
android:maxLines="4"
android:backgroundTint="#android:color/transparent"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:textSize="#dimen/normal_input_text_size" />
<LinearLayout
android:id="#+id/ll_send"
android:layout_weight="6"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="#dimen/_40sdp"
android:layout_height="#dimen/_20sdp"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:src="#drawable/ic_next_arrow"
android:tint="#color/color_gray" />
</LinearLayout>
</LinearLayout>
I'd like to put attach file icon into EditText for example how it was made into WhatsApp.
if you want to add icon in EditText you can use
android:drawableStart=""
android:drawableEnd=""
android:drawableTop=""
android:drawableLeft=""
android:drawableRight=""
how it was made into WhatsApp. How can I do it?
That is not Custom Edittext
You need to wrap your ImageView and EditText in side a ViewGroup like LinearLayout or RelativeLayout
SAMPLE CODE
<LinearLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:padding="10dp"
android:background="#drawable/test"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_camera" />
<EditText
android:layout_width="0dp"
android:background="#android:color/transparent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:src="#drawable/ic_menu_camera" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:src="#drawable/ic_menu_camera" />
</LinearLayout>
android:background="#drawable/test"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#color/colorPrimary" />
<corners android:radius="25dp" />
</shape>
OUTPUT
You need to put edittext and attach icon in layout (according to your need) and set rounded background to parent layout
like this
<RelativeLayout
android:id="#+id/sendLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/roundedbg"
android:orientation="horizontal">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/attachFile"
android:background="#null"
android:padding="#dimen/five_dp" />
<ImageView
android:id="#+id/attachFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
/>
</RelativeLayout>
roundedbg.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="3dp" android:color="#B1BCBE" />
<corners android:radius="10dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
better you use wrap edittext and imageview in relative layout like below
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/custom_edittext"
android:hint="Password"
android:minLines="10"
app:passwordToggleEnabled="true"
android:singleLine="true"
android:inputType="textPassword"
android:textSize="14sp"
android:paddingLeft="20dp"
android:layout_weight="1"
android:paddingRight="20dp"
tools:ignore="MissingPrefix" />
<ImageView
android:id="#+id/ivPasswordToggle"
android:layout_width="24dp"
android:elevation="10dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:layout_height="24dp"
android:background="#drawable/ic_remove_red_eye_black_24dp"/>
</RelativeLayout>
output :
in java code use click on imageview

Android layout Issue - showing differently on different devices.

I have some xml which working fine with api level above 17 but showing differently on phones api below same. My minSDK is 15.
Should i make layout v-17 , v-16 , v-15 separately or is there any other way around which works for all three at once.?
XML showing different behaviour on devices:
<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:id="#+id/verify_number_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/app_name_id"
android:layout_marginLeft="17dp"
android:layout_marginRight="17dp"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:visibility="visible"
tools:context=".activities.LoginActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="46dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="24dp"
android:layout_marginTop="30dp"
android:background="#drawable/outline"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1">
<customViews.TextViewPlus
android:id="#+id/tv_state_code"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:gravity="center|center_horizontal"
android:text="#string/country_code_text"
android:textColor="#color/text_color"
android:textSize="16sp"
app:font="OpenSans-Regular.ttf" />
<View
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="#android:color/white" />
<customViews.EditTextPlus
android:id="#+id/et_mobile"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center|center_horizontal"
android:layout_marginLeft="8dp"
android:layout_weight="0.7"
android:gravity="start|center_vertical"
android:hint="#string/mobile_number_hint"
android:imeOptions="actionDone"
android:inputType="phone"
android:maxLength="10"
android:maxLines="1"
android:background="#android:color/transparent"
android:textColor="#color/textview_color_selector"
android:textCursorDrawable="#null"
android:textSize="16sp"
app:font="OpenSans-Regular.ttf" />
</LinearLayout>
<customViews.ButtonPlus
android:id="#+id/next_button"
android:layout_width="match_parent"
android:layout_height="46dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="24dp"
android:layout_marginTop="8dp"
android:background="#drawable/outline"
android:gravity="center"
android:text="#string/next_button"
android:textColor="#color/textview_color_selector"
android:textSize="17sp"
app:font="Oswald-Light.ttf" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_gravity="center_horizontal"
android:indeterminate="true"
android:indeterminateTint="#color/text_color"
android:visibility="invisible" />
</LinearLayout>
outline.xml drawable used above and showing differently :
<?xml version="1.0" encoding="utf-8"?><!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<stroke
android:width="0.7pt"
android:color="#FFFF" />
<corners
android:bottomLeftRadius="55dp"
android:bottomRightRadius="55dp"
android:topLeftRadius="55dp"
android:topRightRadius="55dp" />
</shape>
above xml image on device above 17:
image on below api 17:
Please suggest some way around.
I think your corners value is to large(larger than half of view height) in your background drawable.
Try like this:
<corners
android:bottomLeftRadius="23dp"
android:bottomRightRadius="23dp"
android:topLeftRadius="23dp"
android:topRightRadius="23dp" />
Please modify the corners Drawable and change the Radius.Need to decrease the Radius size like this-
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<stroke
android:width="0.7pt"
android:color="#FFFF" />
<corners
android:bottomLeftRadius="25dp"
android:bottomRightRadius="25dp"
android:topLeftRadius="25dp"
android:topRightRadius="25dp" />
</shape>
Thanks

how to create textview with the image and border like the image attached

I want to create a textview like the below image. I tried but not able to get like this format.
This is my xml file.
<View android:background="#ff340c1c"
android:layout_width="fill_parent"
android:layout_height="0.5dip"
android:layout_above="#+id/genere"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/genere"
android:text="Search by Movie Genere"
android:layout_above="#+id/rating"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="78dp"
android:textSize="20sp"/>
<View android:background="#ff340c1c"
android:layout_width="fill_parent"
android:layout_height="0.5dip"
android:layout_alignBottom="#+id/genere"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
Use custom background with border and drawableLeft -
drawable/my_rect.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="0.5dp"
android:color="#color/gray" />
<solid android:color="#color/white" />
<corners android:radius="0px" />
</shape>
In XML:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/genere"
android:text="Search by Movie Genere"
android:layout_above="#+id/rating"
android:drawableLeft="#drawable/someimage" // ADD
android:background="#drawable/my_rect" // ADD
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="78dp"
android:textSize="20sp"/>
Note: Many possible solution exists.
It can be done by using a simple linear layout as a border.
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EEEEEE"
android:orientation="horizontal"
android:padding="1dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_search_category_default" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Search By Venue" />
</LinearLayout>
</LinearLayout>
For adding an image to the TextView, see android:drawableLeft. For adding a border, you could take a look at 9-patch images. Generate a 9-patch image as described, and set that as the background of the TextView.

Android: Adding a divider into a list item with dynamic height

I'm currently trying to create a list item similar to the one in the official design guidelines. Still missing is the vertical divider next to the button/image on the right side of each item. Most people seem to use a separate View with a fixed width for that, but the height doesn't scale in my case. It's only shown when I set a fixed height for the divider itself or the parent RelativeLayout. Is it possible to let it scale automatically?
My layout XML for the list item looks like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/sensors_list_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="10dp" />
<TextView
android:id="#+id/sensors_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_toRightOf="#id/sensors_list_img"
android:paddingTop="5dp" />
<TextView
android:id="#+id/sensors_list_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_below="#id/sensors_list_name"
android:layout_toRightOf="#id/sensors_list_img"
android:paddingBottom="5dp" />
<ImageView
android:id="#+id/sensors_list_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:padding="10dp"
android:src="#drawable/ic_angle_right" />
<View
android:id="#+id/sensors_list_divider"
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_toLeftOf="#id/sensors_list_details"
android:background="#ff0000" />
</RelativeLayout>
Try to assign an height related to the image like:
android:alignTop="#id/myimage"
android:alignBottom="#id/myimage"
otherwise you can create a xml drawable and use it with an ImageView :
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="1dp" android:color="#000000"/>
</shape>
Update
Remember android:shape="line" doesn't work without stroke
Let's go with a LinearLayout as a parent:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/sensors_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="5dp" />
<TextView
android:id="#+id/sensors_list_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:paddingBottom="5dp" />
</LinearLayout>
<View
android:id="#+id/sensors_list_divider"
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#ff0000" />
<ImageView
android:id="#+id/sensors_list_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="#drawable/ic_angle_right" />
</LinearLayout>
Check this
listView.setDividerHeight(1);

Android layout _background fit it's content

I am trying to design a custom dialog.
The problem I met was..the background of the textview ,which is the body of the dialog can't change whenever the text get more line ..
wrap_content didn't work ....
PS (there are there part , title , content, buttons )
( title and content are two TextView with two image as background)
one line is fine
but when lines increased... they were eaten !!
if I use wrap_content ... it goes too big !
https://www.dropbox.com/s/in78b8gg0hfkfxh/toobig.png
here is the code of xml
`
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
>
<LinearLayout
android:id="#+id/dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="120dip"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dip"
android:orientation="vertical"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/title"
android:text="Title"
style="#style/TitleStyle"
android:gravity="bottom|center_horizontal"
android:paddingBottom="15dip"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="89dip"
android:background="#drawable/content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="L\na\ny\no\nu\nt\n"
android:gravity="center"
style="#style/TextStyle"
android:paddingRight="20dip"
android:paddingLeft="20dip"
android:paddingTop="10dip"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="0dip"
android:paddingTop="0dip" >
<Button
android:id="#+id/dialog_button_cancel"
android:layout_width="0dip"
android:layout_height="51dip"
android:layout_weight="0.50"
style="#style/BtnStyle"
android:background="#drawable/btn_action"
android:src="#drawable/btn"
android:text="取消"
android:gravity="center"
/>
<Button
android:id="#+id/dialog_button_ok"
android:layout_width="0dip"
android:layout_height="51dip"
android:layout_weight="0.50"
android:background="#drawable/btn_action"
android:src="#drawable/btn"
android:layout_marginLeft="10dip"
style="#style/BtnStyle"
android:text="確定"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>
`
For second (content) TextView wrapper (LinearLayout) try to use wrap_content instead of fixed layout height 89dip:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="L\na\ny\no\nu\nt\n"
android:gravity="center"
style="#style/TextStyle"
android:paddingRight="20dip"
android:paddingLeft="20dip"
android:paddingTop="10dip"
/>
</LinearLayout>
Edit: If the problem is in the image (by the image IMHO you mean white rectangle which wraps title and content views) try to set up rectangle in background in XML instead of an image usage you use for now:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/listview_background_shape">
<stroke android:width="2dp" android:color="#ffffff" />
<padding android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp" />
<corners android:radius="5dp" />
<solid android:color="#8000000" /> <!-- transparent -->
</shape>
Details here: Can I draw rectangle in XML?

Categories

Resources