Overlap image over two rows in a listview - android

I need create a listview with pinned overlay image over upper row and next row, like image example below.
Thanks a lot.

set the Layout parameters of image, ie size not exceed to the parent view
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30);
yourImageView.setLayoutParams(layoutParams);

Related

Android Overlapping Image Views and clickable

Hi, I want to create this sort of a view where there should be a center image view and others overlapping it and i want it to be clickable. How can I achieve this?
You should be able to make it using just RelativeLayout and ImageView.
RelativeLayout lets you overlap views and position it anyway you want.
For getting the touches you can set OnClickListeners to each of the images.
Example:
RelativeLayout rl = new RelativeLayout(this);
ImageView img1 = new ImageView(this);
//Set imageView bitmap
img1.setDrawable("Img");
//Click of the image
img1.setOnClickListener(new View.OnClickListener(){...});
//Size of the image
RelativeLayout.LayoutParams prms = new RelativeLayout.LayoutParams(width,height);
//Rules for position the view on screen
prms.addRule(...)
//Add image to layout
rl.addView(img1,prms);
setContentView(rl);
Z order is the order items are added to the layout.
Hope this helps.

Center view in android after changing its width properties

I'm changing the width of a grid view based on its column width and number of columns (which works):
gridView.setLayoutParams(new LinearLayout.LayoutParams(gridManipulation.getColumnWidth() * (int)Math.sqrt(str.length) + 10, LayoutParams.FILL_PARENT));
gridView.setGravity(Gravity.CENTER);
I've tried re-centering it in the parent view but its not working, does anyone know why, its still centred as if it still has the width parameters before my dynamic change.
Set the Gravity as LayoutParams property then set that LayoutParams to your GridView as follows...
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(gridManipulation.getColumnWidth() * (int)Math.sqrt(str.length) + 10, LayoutParams.FILL_PARENT);
params.gravity = Gravity.CENTER;
gridView.setLayoutParams(params);
you cant center it if its bigger than its parent, which is never bigger than the screen, unless you set it manually, which will cause the system to render data outside the screen and slow you way down.....
is it expanding verticaly or horizontally or both? my recomendation would be to put it in a scrollview.

Displaying Saved Bitmaps in Android (LinearLayout)

I have 2 bitmaps that I saved with view.getDrawingCache(); called firstBitmap and secondBitmap. They were saved from initial drawings made by the user. Now I want to display them. My issue is that only the first picture is displayed by itself (I want both to be shown at the same time). I know that the bitmaps are correct because if I remove layout.addView(pic1), I can see the second image by itself clearly. layout is a LinearLayout.
My suspicion is that the size is an issue but I believe that by default views that are added to the layout have fill parent so this should still result in 2 images not one. I have tried dynamically changing the width and size with LayoutParams but this makes the image disappear entirely. I am open to any suggestions.
ImageView pic1 = new ImageView(this);
pic1.setImageBitmap(firstBitmap);
layout.addView(pic1);
ImageView pic2 = new ImageView(this);
pic2.setImageBitmap(secondBitmap);
layout.addView(pic2);
Try to distribute the weight in your linear layout so that both bitmaps will be visible.
you could use the below code to do that.
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height, weight);
layout.addView(pic1, params);
layout.addView(pic2, params);

background for textview can be scaled programmatically?

i need to create balls with numbers in the middle . i need about 10-11 balls in a row so i use weight .
but my balls (background's for textview don't think dirty) are not circle . i want them to save there own proportions .
LayoutParams textParams = new LinearLayout.LayoutParams(0,
LayoutParams.WRAP_CONTENT, 0.09f);
resultNumber = new TextView(context);
resultNumber.setBackgroundResource(R.drawable.ball_golden);
resultNumber.setGravity(Gravity.CENTER);
resultNumber.setLayoutParams(textParams);
resultNumber.setText("6");
resultLayout.addView(resultNumber);
this is the code , resultNumber added about 10 time for each row .
thanks for your time (-:
You can use a relative layout and position the text view in center for each item. Apply the background resource to the relative layout.

Adding a margin to ImageView programmatically

I have a table layout where each row is built programmatically.
The structure is basically, for each row:
TextView, LinearLayout, LinearLayout, LinearLayout, Button.
Each of the LinearLayout has multiple ImageViews inside of them. I want to increase the spacing between the ImageView items as they render with their borders touching.
I tried the suggestions here - In Android, how to make space between LinearLayout children? - I create the parameters like so:
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent);
And set it like this to an image view when adding the control:
linearLayout1.AddView(image1);
linearLayout1.AddView(image2, layoutParams);
linearLayout1.AddView(image3);
Note I am only setting it on the middle item as a left & right margin on this would be fine for what I am trying to achieve.
The problem is that even without setting any margins on the layout params i.e. just instantiating it and setting it as shown above, it adds about a 35px margin to the left causing a much larger margin than I wanted. Even calling SetMargins with 1px doesn't change the margin.
Where am I going wrong?
set width of linear layout as WrapContent like this
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);

Categories

Resources