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.
Related
For example I already have 7 buttons in a GridView, i just want that in place of 8th and 9th button i get one image.
Is it possible to do anything like that?
Yes it's possible,
as pointed in this answer:
GridView shows a grid of Views. It can show anything that extends View
class. It can show a LinearLayout with an ImageView and an ImageButton
inside it.
but the only possible thing to achieve what you looking for is by creating a custom GridView that has a customized view element as pointed in this answer:
Create an XML which will hold the container GridView, say, grid.xml:
<GridView
android:id="#+id/gridFriends"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipChildren="true"
android:columnWidth="100dp"
android:fastScrollEnabled="true"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>
And, to define the contents of the GridView, create another XML layout which will hold your elements, like Button and ImageView in your case: grid_element.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<FrameLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center" >
<Button
/>
<ImageView
/>
</FrameLayout>
</RelativeLayout>
finally, after declaring the GridView and assigning grid_element.xml as the GridAdapter view type, just iterate over every element and set the Visibility of it's children as Visible , Gone respectively or Gone, Visible respectively according to if you want to make the Button visible or the ImageView. And to set the onClick for the Buttons:
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
if(position != 8 && position != 9){
// do onClick work
}
}
});
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"
I'm using an expandable list view in an alert dialog (custom).
I am setting the view for the list like this:
alertDialogBuilder.setView(myView);
However i notice that the list doesn't stretch to occupy the whole view and i have to scroll within that list as shown in the image below:
Here's my xml code as well:
<ExpandableListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listview"
android:layout_width="match_parent"
android:background="#android:color/white"
android:groupIndicator="#null"
android:scrollbars="none"
android:layout_height="wrap_content"
/>
Has anyone ever had this problem before or know how to tackle it, i could set the height of the expandable listview but i wan't to refrain from that.
In my layout I need a custom list view like a box type.
How can do that ?
My XML:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="317dp"
android:gravity="top"
android:orientation="vertical"
android:background="#android:color/transparent"
>
<ListView android:id="#+id/slistview"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:divider="#2867EA"
android:dividerHeight="1dp"
android:cacheColorHint="#00000000"
>
</ListView>
</LinearLayout>
You should create custom list adapter and supply xml layout for each row.
here's a comprehensive tutorial that fits your needs:
Link
You can use customBaseadapter and viewHolder ...
Create a xml for row of the list view and set the background of the row and create a custom adapter and set adapter to list view.
custom list view
I am doing a task which retrieves images from server and displays in GridView in the application. This Grid view is scrolling up and down. But i want to scroll this view left to right as the menu screen scrolls. Is it possible with grid view? Or Is there any better way to do this? please help me in doing this
Add this line in your gridview.
android:scrollbars="horizontal"
for ex:
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animationCache="true"
android:numColumns="3"
android:scrollbars="horizontal"
android:scrollingCache="false" >
</GridView>