How do I define grid-lines for a GridView?
Is there an attribute or do I have to draw my own background with them in it?
There is no such attribute. The easiest thing is to create a subclass of GridView and override dispatchDraw() or onDraw() to do it yourself.
set the background to the view(inflate layout) inside the GridView so that gridview display the line automatically.
You can just set a padding for each cell of the grid view so that that looks like the grid line. Each cell say would be made up of a linear layout.
Another way of doing this would be to have the cell as a linearlayout and have a view inside that with width of say 0.5dp and height as mp and vice-versa for the horizontal line.
Related
I have a recyclerview set up with a linear layout at horizontal where each imageview takes up the full width of the visible recyclerview. I was wondering how to fix this such that the imageview items are next to each other the way you'd see this in a carousel. A copy of what I'm seeing is found below. Thanks!
In your layout item, which you are inflating using the adapter class.. you should define the width of the layout as either wrap_content or a fixed value(for eg: 200dp or something else according to your need). I think you have used match_parent that's why you are facing such an issue.
Feel free to ask if something is unclear.
Looks like the ImageView has been resized based on the layout_height specified and you have a value of wrap_content on the layout_width. You should set the ImageView's attribute android:adjustViewBounds to true.
Reference: https://developer.android.com/reference/android/widget/ImageView#attr_android:adjustViewBounds
how can i mange Textview in layout.? please help me..
how can i set textview and border then again textview.
Just create a horizontal LinearLayout, and add an ImageView, a TextView, a View with width 2dp and height match_parent, and a TextView as children.
Either repeat that for every row, or use the recommended approach of using a ListView with the above mentioned layout as rows.
I'd use two compound TextViews: Just create a horizontal LinearLayout, and add a TextView with drawableLeft="#drawable/icon_location" and another one with drawableLeft="#drawable/line_vertical" as children.
For both, a drawablePadding="8dp" or whatever you like best
I would like to create a custom View (that will be inflated from XML) which will be drawn at given x\y coordinates.
I know I can create a custom View which will implement onDraw(Canvas canvas), but I want this View to be inflated from XML.
On Canvas I can only draw lines, rectangles and such.. But I want to inflate a whole XML layout..
How can I do that??
You can use a FrameLayout as a main layout.
Inflate the layout you want.
Add it to the FrameLayout.
Then add padding / margin with LayoutParams.
I've ended up using RelativeLayout as mentioned here:
Set the absolute position of a view
Thanks for the answers!
I want to layout my views in the following way: [Button] [SomeView] [Button]. I want to set specific sizes for buttons (in mm), and then have the SomeView fill the remaining space between them.
How to achieve this?
Maybe you could set the layout:weight of the [SomeView] to 1 and put all of these views in a linearlayout. Hope it works!
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!