I am trying to change the size of the items within my GridView. Currently the items are arranged by style (GridView_words_small) in an xml:
numColumns: auto_fit
stetchMode: 'spacingWidth'
ColumnWidth: width of the items being added (resource).
Now, through a settings change, the buttonsize can be changed. However, when I setColumnWidth() and invalidate(), no items are displayed (leaving the area blank.)
Does anyone know how to properly change gridview column widths dynamically?
Related
I have a recyclerview with bunch of textview each as an item as you see in picture below. (Blue lines aren't really there, i added them so you can see each item separately) as you can see everything seems nice and user will not notice the text is separated.
The problem is when user increases the line space(a typical option in app) line height gets bigger except the first and last line of each item and the result seems like second picture.
My question is how to find appropriate padding to set to each item so every line height seen exactly the same?
BTW i can not use just one textview for many reason!
You can increase the divider height of your listview according to linespacing height.
Or you can set an invisible view at the bottom of every row item and increase the height of this view according to linespacing height.
Or you can set padding at the bottom of every row item and increase the value of this padding according to linespacing height.
just add some padding to the parent of your textview in the layout file of your list item .
for example the layout with linearlayout would be like :
<LinearLayout ........
paddingTop=15dp>
<TextView
..........>
</TextView>
</LinearLayout>
and you could adjust the padding dynamically if you want.
i am trying to implement ListView. Problem is that when i am showing items of list less that the scree size the remaining is showing black. I want to set any image so that when items are less than screen size then background should be a picture
put your <ListView /> inside <LinearLayout/> ,
add background to Linear layout, with LL Height as match_parent and hieght of Listview as wrap_content
I have not done this myself, but this is what I think should work.
Place the image in /res/drawable
Then add these lines to activity in manifest or to parent layout of ListView
android:scaleType="fitCenter"
android:background="#drawable/image_name"
Let me know how that goes.
Good day all, have a small issue here. I have an EditText and a ListView inside a RelativeLayout. The ListView is populated by items in a string-array using an ArrayAdapter. The size of thr array is 5 and the ListView Items is a Table Layout with table row Layout Parameters set to both Fill_Parent same as the ListView Widget. Now I want the Listview Items to fill up and occupy the remaining screen space. but since they are only few Items, it behaves like it's using wrap_content. Any Idea how to stretch out this ListView Items? Thanks in Advance.
Try this out:
<ListView
android:id="#+id/yourListView"
android:layout_width="fill_parent"
android:layout_height="match_parent">
</ListView>
In iOS programming I have to implement (or at least if I don't want the default one...) an method which returns the height of the row. I am probably blind because I can't find the method where I set the height of the row in a listview in Android.
I have created custom row layouts, so I start to think that I set the height in the parent layout manager in the XML. Can anyone confirm that this is the way to do it? Or is it a method?
You'll need to set the height in the layout xml for the row itself. If you absolutely want every row to be the same height, set:
android:minHeight="80dp"
android:maxHeight="80dp"
in your base layout (Should be a LinearLayout or RelativeLayout, likely) of the listview row. Note you can do:
android:minHeight="?android:attr/listPreferredItemHeight"
android:maxHeight="?android:attr/listPreferredItemHeight"
to be inline with (most) other applications.
Yes, the only way to set the height of the row is to mention it's dimensions in the xml ,for the list item or you can also set the height of the list item in the getView() method of listView if you have a custom Adapter. There is no listView method as such to define the height of the row.
Is there a way to force GridView to only be a single row? Right now by default it will extend its height to accommodate all views supplied by its adapter
You Should combine a horizontal SCROLLVIEW and a LINEARLAYOUT and a GRIDVIEW to achieve what you want!
put grid view in linearlayout and put the linear layout in the horizontal scroll view;
then when setting adapter! count the number of data!
after that you should calculate the desired width to show all your items!
for example you want to show 8 item! each width is 100dp . so the desired width would be 800dp!
then you should add these lines of code
yourGridView.setNumColumns(8);
LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(800, ViewGroup.LayoutParams.MATCH_PARENT);
yourGridView.setLayoutParams(lp);
dnt forget to set the width of the linear layout as WRAP_CONTENT in the xml!
*** IMPORTANT NOTE
as i know, by doing this, gridview can't garbage collection because Scroll View doesn't support such a thing and your grid view nested in it!
so dnt use this method for lots of images or you will get HEAP SIZE error!