I have a gridview of images, i need to add one drawable image as a separator between images in gridview.
anyone help me how to add.?
try this hope help
list_item.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:orientation="horizontal"
android:background="#drawable/list_selector">
<!-- Cell contents -->
</LinearLayout>
list_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:drawable="#drawable/item_border_selected"
/>
<item
android:state_pressed="true"
android:drawable="#drawable/item_border_selected"
/>
<item
android:drawable="#drawable/item_border"
/>
</selector>
item_border.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#android:color/transparent"
/>
<stroke
android:width="1px"
android:color="#color/list_divider"
/>
</shape>
item_border_selected.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#color/list_select"
/>
<stroke
android:width="1px"
android:color="#color/list_divider"
/>
</shape>
items_view.xml
<?xml version="1.0" encoding="utf-8"?>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="-1px"
android:layout_marginRight="-1px"
android:listSelector="#android:color/transparent"
/>
Since all lines double in size as they join their neighboring cells, I made the divider size 1px instead of 1dp so it doesn't appear too large on some screens. Also, I made the grid view have negative margins to hide the lines on either side. I hope this helps someone.from here
Related
I'm working on an android keyboard application. As you know key object can set an icon or label for itself , so now I wanna set a re-sizable rounded rectangle for space keyboard button like This one
I wanna make it able to be resized when it's running on large screens , I have this in my keyboard xml class :
<Key android:codes="46" android:keyIcon = "#drawable/space_button_drawable.xml">
what should I have in my space_button_drawable.xml ?
EDIT 1 :
buttonbgselector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="false"
android:drawable="#drawable/button" />
<item
android:state_pressed="true"
android:drawable="#drawable/button2" />
</selector>
keyboard.xml
<?xml version="1.0" encoding="UTF-8"?>
<android.inputmethodservice.KeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:keyBackground="#drawable/buttonbgselector"
android:keyPreviewLayout ="#layout/preview" />
space_button_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="10dp" />
<solid
android:color="#AAA" />
</shape>
use this drawable in your background of LinearLayout keyboard.xml
I've tried several combinations of selectors, but the end result is the same. Even though the selector is displayed correctly, if I go up or down the selector stays in the middle of the screen. It's exactly this issue, but I couldn't make it work with this or any other solutions I've found.
Here I am selecting a row:
And then scrolling down:
My ListView:
<ListView
android:id="#+id/cardListView"
android:background="#android:color/black"
android:listSelector="#drawable/list_view_selector"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
My list_view_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:drawable="#drawable/background_selected" />
<item
android:drawable="#drawable/background_selected" />
</selector>
And my background_selected
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:centerColor="#ffffff"
android:endColor="#ffffff"
android:startColor="#ffffff" />
</shape>
Thanks in advance.
In my application I have a ListView with custom rows and I want to add a custom CheckBox for each item, like this:
When I click on 'EDIT' I want the ListView translates to right and it appears a custom CheckBox at left from each ListView's row.
Is it possible to maintain the ListView at right even if some row icons don't seen (like the star or arrow)? Or if I translate the ListView at right the row is compressed and all icons are visible?
I have put a TranslateAnimation:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:fromXDelta="0%"
android:toXDelta="17%"
android:duration="750" />
</set>
and I have managed to translate the ListView but after 2 seconds it returns to the initial position ... how can I manage that the ListView maintains at right after TranslateAnimation?
Is it better to put a checkbox like 'gone' at left to the row and when 'EDIT' button is pushed to put all checkbox like visible? In this case, Does each row translate to right like the image or it would be compressed and all icons would be visible?
Thanks
EDIT:
My row xml file:
<?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="#color/backgr_greysoft" >
<LinearLayout
android:id="#+id/row_information"
android:layout_width="fill_parent"
android:layout_height="#dimen/rowDescargas_height"
android:background="#drawable/button_file"
android:descendantFocusability="blocksDescendants"
android:layout_margin="#dimen/rowDescargas_marginLateral"
android:orientation="horizontal"
android:weightSum="1" >
<ImageView
android:id="#+id/icon"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_margin="#dimen/rowDescargas_marginIcono"
android:layout_weight="0.25" />
<LinearLayout
...
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Yes, put a checkbox like gone. And set to your information view following:
android:layout_width="0dp"
android:layout_weight="1"
Parent of this view should be LinearLayout with android:orientation="horizontal".
custom_checkbox.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="#xml/checked" />
<item android:state_pressed="true"
android:drawable="#xml/checked" />
<item android:drawable="#xml/unchecked" />
</selector>
checked.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#ff2665B4" android:endColor="#ff2665B4" android:angle="270"/>
<stroke android:width="4px" android:color="#ffc0c0c0" />
<size android:height="20dp" android:width="20dp"/>
</shape>
unchecked.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#ffffff" android:endColor="#ffffff" android:angle="270"/>
<stroke android:width="4px" android:color="#ffc0c0c0" />
<size android:height="20dp" android:width="20dp"/>
</shape>
set in to checkBox
facilityCheck.setButtonDrawable(R.xml.custom_checkbox);
<?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="#color/backgr_greysoft" >
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/chk_facility"
android:layout_alignParentLeft="true"
/>
<ImageView
android:id="#+id/icon"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_margin="#dimen/rowDescargas_marginIcono"
android:layout_toRightOf="#+id/chk_facility" />
</RelativeLayout>
I have a selector for different states of the list view. I have selected a grey colour for the background but its not working ,pressed state is working fine but my list view background is still white, and when I select the list item its colour changes to grey which I have chosen for the background and the background is still white.
Please help ,Sorry for the silly question as I am new to android.
My list view is:
<?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="match_parent"
android:background="?android:attr/activatedBackgroundIndicator">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector">
</ListView>
</FrameLayout>
Selector xml is:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="#drawable/gradient_bg" />
<item android:state_pressed="true"
android:drawable="#drawable/gradient_bg_hover" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="#drawable/gradient_bg_hover" />
</selector>
pressed_state xml is:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#78DDFF"
android:centerColor="#16cedb"
android:endColor="#09adb9"
android:angle="270" />
</shape>
background xml is:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#D5DDE0"
android:centerColor="#e7e7e8"
android:endColor="#CFCFCF"
android:angle="270" />
</shape>
Apply your selector to the ListView item, I mean the viewgroup of the row.xml or whatever name you have defined for the listview item.
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>"
>