I added a divider to my listview but there is nothing there. The ListView stays comepletely the same as if there wasn't any divider set.
This is ListView XML:
<ListView
android:id="#+id/listview_language"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#drawable/shadow" />
#drawavble/shadow XML:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
>
<shape
>
<gradient android:startColor="#color/shadow_start"
android:endColor="#color/shadow_end"
android:angle="90"/>
<stroke
android:height="1dp"/>
</shape>
</item>
</selector>
Why won't the divider appear on ListView?
you should also add the android:dividerHeight property to your layout
Try to replace selector root element with layer-list in your shadow xml file.
Related
I'm trying to add strokes to a view using drawable.
But I want add it only in side parts(left and right), not in whole parts.
Is there any good way to add stroke in side parts?
Below is my drawable xml code. (leanear_border_gray.xml)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp"
android:color="#778899"/>
</shape>
and below is my target view xml code.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/linear_border_gray"
android:layout_weight="1">
....
</LinearLayout>
You need to wrap your shape into layer-list drawable with rectangular shape, add stroke and using top and bottom margins with negative values "hide" top and bottom lines, like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-4dp" android:bottom="-4dp">
<shape android:shape="rectangle">
<stroke android:width="2dp" android:color="#778899"/>
</shape>
</item>
</layer-list>
You can do it by using layer-list drawable suggested by #iDemigod
Your Layout should be like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_marginTop="20dp"
android:background="#drawable/border_left_right"
android:layout_gravity="center"
android:layout_weight="1">
</LinearLayout>
Note: If you are giving android:layout_height="match_parent" and android:layout_weight="1" then you must have to set android:layout_width="0dp" and vice versa for android:layout_width="match_parent".
File: border_left_right.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-4dp" android:bottom="-4dp">
<shape android:shape="rectangle">
<stroke android:width="2dp" android:color="#07060b"/>
</shape>
</item>
I'm wondering if it's possible to change the color of the ScrollView.
I'm not referring to the background color or the edges.
I attached a print screen of the bar I'm referring. For me, it's kind of transparnt.
Here's how I defined it in the xml:
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fadeScrollbars="false"
android:layout_toLeftOf="#+id/personalscores_BackButton"
android:layout_marginRight="0dp" >
Create a scroll bar in drawable(scrollbar.xml) using this
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="45"
android:centerColor="#65FF8215"
android:endColor="#87FD2125"
android:startColor="#65FF8215" />
<corners android:radius="20dp" />
</shape>
and add this scroll bar like android:scrollbarThumbVertical="#drawable/scrollbar" to your ListView
OR
put the following attribute to your layout
android:scrollbarThumbVertical="#android:color/white"
OR
create a image and put it in drawable. then add the following property to your layout
android:scrollbarThumbVertical="#drawable/scroll_bar_vertical"
put the following attribute to your layout
android:scrollbarThumbVertical="#android:color/white"
or create a image and put it in drawable. then add the following property to your layout
android:scrollbarThumbVertical="#drawable/scroll_bar_vertical"
Try this beautiful custom scrollview
Add following tags in your scrollview
android:fadeScrollbars="false"
android:scrollbarStyle="insideInset"
android:scrollbarThumbVertical="#drawable/scrollview_thumb"
android:scrollbarTrackVertical="#drawable/vertical_scrollview_track"
Create following drawable in your drawable folder
scrollview_thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/common_google_signin_btn_text_light_focused" />
<corners android:radius="15dp" />
</shape>
vertical_scrollview_traack.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#E2E0EB" />
<stroke
android:width="1dp"
android:color="#b3a9a9" />
<size android:width="15dp" />
<corners android:radius="15dp" />
</shape>
Output
Taken from this question:
You can set Listview property as or put the following attribute to your scrollview:
android:scrollbarThumbVertical="#drawable/custom_scroll_style"
Here custom_scroll_style is a xml file under the drawable folder. Lets create the custom_scroll_style.xml.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="45"
android:endColor="#FF3401"
android:centerColor="#ff5c33"
android:startColor="#FF3401" />
<corners android:radius="8dp" />
</shape>
The question is: "how to change color"
The only correct answer is one! code line in your layout:
android:scrollbarThumbVertical="#android:color/white"
Thats all!
p.s.
The question is simple: "color"! and the answer is very simple too.
Not a: "how to set custom bar", "how to change bar sizes" or etc.
Why so many long answers...
I have a listview and I want to have a background gradient that covers the entire listview. I don't want a gradient for each row. All I get is a white background.
Code for gradient in mybg.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:startColor="#e6e6e6"
android:endColor="#ffffff"
android:angle="45" />
</shape>
</item>
</selector>
My ListView:
<ListView
android:id="#+id/lvEvents"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#drawable/mybg"
android:cacheColorHint="#00000000"
android:divider="#ffc0c0c0"
android:dividerHeight="1dp"
android:scrollingCache="true" />
Try set the row view background to be transparent by using #null.
You missed the shape , try this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="270"
android:centerColor="#000000"
android:endColor="#404040"
android:startColor="#404040" />
</shape>
This is my code which work fine, I just want to add border at top and bottom of listview. So, My question is how to add border at top and bottom of listview. Note: I just want to add only border and where I can place border? Any help will be appreciated. Thanks
<ListView android:id="#+id/listCategory"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="true"
android:fastScrollEnabled="true"
android:listSelector="#drawable/listview_selector"
android:dividerHeight="1dp"
android:layout_below="#+id/gridlayout"
android:visibility="gone"/>
listview_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true" android:drawable="#drawable/listview_selector_focussed" />
<item android:state_pressed="true" android:drawable="#drawable/listview_selector_pressed" />
</selector>
listview_selector_focussed.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#0a89f1" android:endColor="#56768d" android:angle="90" />
</shape>
listview_selector_pressed.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#0a89f1" android:endColor="#56768d" android:angle="90" />
</shape>
Add a header and footer, they will serve you as a border
In your Activity where you will declare your ListView;
View v=new View(this);
v.setLayoutParams(new LayoutParams(<width>,>height>));
v.setBackgroundColor(<your color>);
ListView list=(ListView)findViewById(R.id.listCategory);
list.addHeader(v);
list.addFooter(v);
In your layout file at your parent layout element
<YourParentLayoutElement
...
android:paddingTop="<your_value>"
android:paddingBottom="<your_value>"
>
In the attached screenshot of the Gmail app, the ListView's background seems to have a vertical gradient on the right side of the list to separate from the neighboring View.
I know I can define a GradientDrawable in xml, but how can I use this to draw a gradient as the background of one side of the list, while drawing the rest of the list's background as light grey?
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#DDDDDD"
android:endColor="#CCCCCC"
android:angle="0" />
</shape>
You just assign your the cutsom drawable you created as the background attribute of your ListView item. You can do this in the XML layout you are using to define your list element.
As an example, I use this layout (list_item.xml) to define a custom layout for my list items (and assign a gradient as a background):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/list_item_gray_gradient"
android:orientation="horizontal"
...
You could create a drawable, and place it to the right of your the Layout containing your list items. So, your gradient is a separate component in your view, that sperated your ListView for the view on the right.
Something like this pseudo-code
<LinearLayout
android:orientation="horizontal"
<ListView
/>
<ImageView
android:background="#drawable/gradient_drawable"
>
>
I can setup the drawable to be 95% light grey, with the gradient on the right half, using the below:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#DDDDDD"
android:centerColor="#DDDDDD"
android:endColor="#CCCCCC"
android:centerX=".95"
android:centerY=".95"
android:angle="0" />
</shape>
First Create this drawable : (drawable/list_gray_gradient.xml)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the line -->
<item>
<shape>
<solid android:color="#CCCCCC" />
</shape>
</item>
<!-- This is the main color -->
<item android:right="10dp">
<shape>
<solid android:color="#DDDDDD" />
</shape>
</item>
</layer-list>
And then just use this to your list item layout: (layout/list_item.xml)
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/list_gray_gradient" >
</RelativeLayout>