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
Related
I have a view (Seekbar) in which i am setting a drawable shape named seek_bar.xml in progressDrawable, but i am getting different result when i run the layout in different level api. Means when i run the layout in <21 the shape size seems too small but when i run the layout >=21 shape size seems perfect, please help me how to fix this api level issue for this layout. See the images.
and my appcompct version is.
compile 'com.android.support:appcompat-v7:23.1.1'
I have a view named confirm.xml code looks like
<LinearLayout
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/dialog_background"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/txt_dia"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginTop="40dp"
android:layout_weight="1"
android:gravity="center_horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/dialog_title_logout"
android:textColor="#color/gray_dark"
android:textSize="#dimen/dialog_text_title"
android:textStyle="bold"
>
</TextView>
<RelativeLayout
android:id="#+id/yes_no_back_strip"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_below="#+id/swipe_btn"
android:layout_marginBottom="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<SeekBar
android:id="#+id/unlockButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:max="100"
android:progress="50"
android:thumb="#drawable/slide_thumb"
android:splitTrack="false"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:thumbOffset="1dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:progressDrawable="#drawable/seek_bar"
/>
<LinearLayout
android:id="#+id/yes_no_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:visibility="visible"
>
<TextView
android:id="#+id/confirm_btn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="left|center_vertical"
android:paddingLeft="15dp"
android:text="#string/btn_txt_yes"
android:textColor="#color/gray_light_high"
android:textSize="#dimen/common_text_size"
android:textStyle="bold"
/>
<TextView
android:id="#+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:paddingRight="15dp"
android:text="#string/btn_txt_no"
android:textColor="#color/gray_light_high"
android:textSize="#dimen/common_text_size"
android:textStyle="bold"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
and my seek_bar.xml is ....
<?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="0"
android:startColor="#ffe0db"
android:centerColor="#aeff6960"
android:endColor="#ff0002"
/>
<corners android:radius="35dip" />
<size android:height="49dp"
android:width="190dp"/>
</shape>
</item>
<item android:id="#android:id/progress">
<clip >
<shape>
<gradient
android:angle="0"
android:startColor="#0b6e07"
android:centerColor="#75ba70"
android:endColor="#97ba93"
/>
<corners android:radius="35dp"
/>
<size android:height="49dp"
android:width="190dp"/>
</shape>
</clip>
</item>
</layer-list>
In api level >20 android:width and android:height not works with shape, i mean it well automatically detect the correct height and width accordingly to the view but it is not the case when you are using the api level <20. So when you fix the min width and height it will remains fixed through out all the api levels.
Otherwise you can specify different -2 layout size.
Just add minHight and maxHight in your seekbar layout
<Seekbar
.....
android:minHeight="50dp"
android:maxHeight="50dp"
....
/>
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=""
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.
ALL,
Everywhere I look I see a reply on how to make it work for application icon. My situation is a little different.
In my program I have a ListView which displays images. Every image is associated with the object underneath.
What I want to do is create a design like in the iPhone badge notification, but for all those images in the view.
Trying to ask Google, I found this link. Problem is - it does not work. I'm testing on the LG Android phone with 2.2 kernel and all I see is the small red dot which is not even located on the image itself couple of pixels higher and to the left.
Here's my 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" >
<ImageView
android:id="#+id/user_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/user_image_description"
android:src="#drawable/placeholder"
/>
<TextView
android:id="#+id/user_messages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/icon"
android:layout_alignBottom="#id/icon"
android:background="#color/red"
android:textColor="#color/silver"
android:layout_marginLeft="-4dp"
android:layout_marginBottom="-4dp"
android:textSize="12sp"
android:textStyle="bold"
android:gravity="center"
/>
</RelativeLayout>
Can someone please look?
I tried to change the margins as well as text size, but it didn't change anything.
Thank you.
Try this way
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dip"
android:focusable="true" >
<ImageView
android:id="#+id/icon"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_marginTop="8dp"
android:background="#drawable/logo"
android:contentDescription="image"
android:scaleType="center" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/icon"
android:gravity="center"
android:paddingLeft="3dp"
android:paddingTop="10dp"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="1.5"
android:text="#string/app_name"
android:textColor="#FFF" />
<TextView
android:id="#+id/txt_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-10dip"
android:layout_toRightOf="#+id/icon"
android:background="#drawable/badge_count2"
android:contentDescription="badge"
android:gravity="center"
android:text="1"
android:textColor="#color/White"
android:textStyle="bold"
android:visibility="visible" />
</RelativeLayout>
Create drawable/badge_count2.xml file like below
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#color/red" >
</solid>
<stroke
android:width="2dp"
android:color="#FFFFFF" >
</stroke>
<padding
android:bottom="2dp"
android:left="7dp"
android:right="7dp"
android:top="3dp" />
<corners android:radius="10dp" >
</corners>
Output:
I'm making an app with it's contents inside card-like views but I am having a couple of problems:
I can't get the label line (the blue line) to move away from the card text. I've tried both padding and margin (on both line imageview and textview from text) and nothing seems to work here.
The bottom part of the card title is getting cropped because of the line spacing. How can I fix this and keep the line spacing?
Check this screenshot for better understanding: http://imgur.com/qsoCFrB
Here's the code to the card background and the interface itself:
card_bg:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="1dp"/>
<solid android:color="#bdbdbd" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="2dp" />
<solid android:color="#android:color/white" />
<padding android:bottom="6dp"
android:left="6dp"
android:right="6dp"
android:top="4dp" />
</shape>
</item>
</layer-list>
main acitivity:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:background="#drawable/card_bg" >
<ImageView
android:id="#+id/iconView0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="6dp"
android:src="#drawable/icon_example" />
<ImageView
android:id="#+id/labelSource0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/cardText0001"
android:layout_marginTop="4dp"
android:background="#drawable/card_label" />
<TextView
android:id="#+id/cardTitle0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/cardText0001"
android:layout_toRightOf="#+id/iconView0001"
android:fontFamily="sans-serif-condensed"
android:maxLines="2"
android:paddingLeft="4dp"
android:lineSpacingExtra="-6dp"
android:text="#string/card_title_002"
android:textColor="#717171"
android:textSize="16sp" />
<TextView
android:id="#+id/cardText0001"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/iconView0001"
android:fontFamily="sans-serif"
android:layout_marginTop="4dp"
android:maxLines="1"
android:text="#string/card_desc_002"
android:textColor="#acacac"
android:textSize="12sp" />
</RelativeLayout>
</FrameLayout>
Thanks in advance.
this is the creator of the Gist on GitHub!
Have you tried increasing padding on the RelativeLayout, perhaps that could fix the problem? Or even on the TextView element?
Try doing that and see what the results are.
EDIT: Also, why is there negative line spacing within the Text View?
DOUBLE EDIT: So what was happening is that your layout_alignBottom in the linkTitle TextView was shorter than the height of two lines of text, therefore it was cropping the title to limit the height of the TextView to that of the FavIcon ImageView. Removing this property fixes the issue.
Similar issue goes for the label shape, that alignBottom is what's messing it up.
Change layout_alignBottom to layout_below and then padding/margin should affect the position as you please.
Here is the updated version of your code that should remedy your issues:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linkCardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ccc" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:background="#drawable/card_bg">
<TextView
android:id="#+id/linkTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/faviconView0001"
android:padding="4dp"
android:maxLines="2"
android:text="#string/link_title_001"
android:textColor="#717171"
android:textSize="17sp" />
<TextView
android:id="#+id/linkDesc0001"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linkTitle"
android:paddingTop="6dp"
android:paddingBottom="9dp"
android:fontFamily="sans-serif"
android:maxLines="1"
android:text="#string/link_desc_001"
android:textColor="#acacac"
android:textSize="13sp" />
<ImageView
android:id="#+id/faviconView0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="6dp"
android:layout_alignParentLeft="true"
android:src="#drawable/favicon_example" />
<View
android:layout_height="0dp"
android:layout_width="fill_parent"
/>
<ImageView
android:id="#+id/labelSource0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linkDesc0001"
android:background="#drawable/card_label" />
</RelativeLayout>
</FrameLayout>
I hope that all of this helps!