I want to display circular images in grid and also a feature to drag and drop the images to reposition the icons. Also I want to add circular images dynamically. So I used grid view and drag and drop framework in android (along with onItemLongClick event listener). Everything works fine. I just dont want the highlight of an item during onItemLongClick. It highlights an item creating a rectangular shadow (This is not the shadow builder as part of the drag and drop framework) behind the circular image. Is it possible to remove that highlight?
Below is the Grid item layout xml.
<?xml version="1.0" encoding="utf-8"?>
<com.steth.CircleImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="#+id/userImg"
/>
Below is the GridView xml.
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_margin="8dp"
android:layout_weight="1" />
Add to your GridView:
android:listSelector="#android:color/transparent"
Related
I want to create a grid view but the default grid view is not useful.
I want to create the same grid view as this image:
Here is my Grid view:
<GridView
android:id="#+id/list_product_grid"
android:layout_width="fill_parent"
android:layout_height="match_parent"
tools:listitem="#layout/products_page_grid_view"
android:numColumns="2"
android:horizontalSpacing="2dp"
android:gravity="center"
android:background="#fff"
android:padding="10dp"
android:visibility="visible"
android:verticalSpacing="2dp"/>
And my snapshot:
To do that you need to build your custom list / grid view using a Fragment list, and use custom a ListAdapter / ListItem for it as shown in this tutorial about List Fragments In Android Studio.
I Created GridView with CheckedTextView as item.
Here my Gridview in XML
<GridView
android:id="#+id/grid_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="auto_fit"
android:horizontalSpacing="5dip"
android:verticalSpacing="5dip"
android:gravity="center"
android:choiceMode="multipleChoice"/>
Here GridView item in XML
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/checkedTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/gray_color"
android:background="#drawable/shape_rectangle"/>
But it displaying two item in a row and each item displaying with extra space like below
how to avoid the extra space in each item in GridView ?
try using match_parent in the item's width & height, not sure what was the problem but ive also encountered this one, tell me if this fixed it, otherwise ill look into my old projects and get you another solution
Is it possible to set borders to grid view in xml. Like, i want each grid cell to contain borders. If so, kindly let me know how to do it. I have set this way. But i am not finding any specific thing to set border.
<GridView
android:layout_marginTop="95px"
android:layout_marginLeft="32px"
android:id="#+id/gridview"
android:layout_width="340px"
android:layout_height="250px"
android:columnWidth="35px"
android:numColumns="7"
android:scrollbars="none"
android:verticalSpacing="14px"
android:horizontalSpacing="18px"
android:stretchMode="columnWidth"
android:gravity="center_horizontal"
android:background="#color/white">
</GridView>
Thank you
Swathi
I've got a basic GridView that I've set up as follows:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/MainMenuGridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
Everything works fine until I add a ninepatch background. Once I add the background image like this:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/MainMenuGridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="#drawable/mainbackground"
/>
It breaks my gridview. Instead of displaying 3-4 columns (depending on screen resolution and orientation) all icons in the gridview display in a single column in the upper left corner. Furthermore, only two at a time are displayed and I have to scroll down to see the rest. I suspect that the gridview is being bound by the dimensions of the ninpatch's center logo, but I'm not sure.
My ninepatch has a small area in the middle with a logo that I want to be displayed without any skewing. The rest of the background is a small gradient that takes up the remainder of the screen. Any ideas on what's causing this?
Sounds like you have padding defined (the lines at the bottom and right of the ninepatch)? Try getting rid of those, so you only have content area defined (the lines at the top and left)
I had a similar problem. Unfortunately I want to use padding in my case. What I found is that the order of method calls on gridLayout seem to make a difference. As long as I called setPadding() after setBackgroundResource(), all is fine.
I am trying to port an existing iPhone application to android. I wish to have a button scroll into view at the bottom of a GridView to enable the user to load more data from the server. Presently, my solution simply fixes a button at the bottom of the screen instead of having it scroll into view.
Here is my layout code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/grid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnWidth="70dp"
android:numColumns="auto_fit"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="#000000"
/>
<Button
android:id="#+id/load_more"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Load More"
/>
</LinearLayout>
Fixing the button at the bottom of the screen won't work because I plan on placing an ad at the bottom.
Can anyone either explain conceptually how to get a load more button to scroll into view, or point me to some sample code, OR tell me why this is not idiomatic to Android and what other UI convention it uses to load more data in a GridView?
Thanks!
You can place a ScrollView inside your main LinearLayout. A ScrollView can only have one direct child, though, so you'll need to put another LinearLayout inside of it which would then contain your GridView and Button.
I had a similar problem with scrolling a GridView and after refreshing the underlying data, noticing that the scoll was not reset to the beginning. I solved it with the following code fragment
gvKeys.setSelection(0);
I'm guessing that if you know the number of items in your grid, N, that the following will work:
gvKeys.setSelection(N);