I was attempting to place a image on top of another existing image in android. Here was the game plan. First the user would select a button and then that button would tell the program to populate a sprite/ image to a fixed location on the master Image. Once the image is set the user could then hit a button for another image on top of what is currently their, (the goal is two images with a option to change their size, x and y position. I am only using android 2.1 platform! The button for selection and the text describing the activity are in a linearlayout.
You should use a RelativeLayout and then you can use params to set position, margin, etc..
something like this:
//this is your fist item
r1.setImageResource(R.drawable.myimage);
//this is the second item
r2.setImageResource(R.drawable.myimage2);
RelativeLayout.LayoutParams imageParams=
new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
imageParams.setMargins(1, 1, 1, 1);
imageParams.addRule(RelativeLayout.BELOW,r1.getId());
addView(r2,imageParams);
Related
I want below mentioned functionality in my app but don't know which widget i should use.
As like above image, user can slide image/view on horizontal bar to pick value, user can pick any value between 0 and 720, There is milestone at every 30 points
Now the main point is as soon as user swipe image to right most on horizontal line, Line must scroll towards left and must change milestones accordingly (Like 90,120,150.....720) so basically its horizontal value picker and user can slide it to pick desired number.
Also user can swipe right to left to select previous values. values are fixed 0 to 720
Try this !! https://github.com/AnderWeb/discreteSeekBar
and try to change the thumb to drawable
Drawable myThumb = getResources().getDrawable(R.drawable.slider_button);
myThumb.setBounds(new Rect(0, 0, myThumb.getIntrinsicWidth(),myThumb.getIntrinsicHeight()));
skbr.setThumb(myThumb);
How can I change the Android SeekBar Thumb drawable after 'onCreate' method?
I am new to android, and I want to achieve below image slide view in which next and preview image should appear a bit. I am using App-intro library. I have stored images in local . I tried with App-intro library but I'm unable to achieve the result. Thanks in Advance.Image slide with next and previous image preview(a bit)
Try below solution to achieve what you want.
viewPager.setClipToPadding(false);
// set padding manually, the more you set the padding the more you see of prev & next page
viewPager.setPadding(40, 0, 40, 0);
// sets a margin b/w individual pages to ensure that there is a gap b/w them
viewPager.setPageMargin(20);
Whatever padding you want on top and bottom specify in xml file
android:paddingTop="30dp"
android:paddingBottom="50dp"
I have a bunch of dynamically created ImageViews representing different objects in a game, which is working fine. However if any Image reaches the edge of the screen, it shrinks. Looks like android is attempting to create a smooth transition, but this is not wanted.
I found another thread with the same issue here: Animation Drawable gets automatically shrinks at the corners ?, however his solution does not work for me, it only enhances the issue as it starts shrinking once the margin hits the screen edge.
This is my code:
final LayoutParams _updated_params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
_updated_params.setMargins((int)m_x, (int)m_y, 0, 0);
m_image.setLayoutParams(_updated_params);</code>
Where m_x/m_y is the absolute position of the image and m_image is an ImageView instance.
Does anyone know how I can turn off this automatic resizing?
Add setScaleType
m_image.setScaleType(ScaleType.MATRIX);
Use setScaleType
m_image.setScaleType(ScaleType.FIT_XY);
is there a way to move the whole screen content outside the screen bounds, with titlebar and all, on the left for example, i tried
content = ((LinearLayout) act.findViewById(android.R.id.content)
.getParent());
to get the screen content and add a margin to it
FrameLayout.LayoutParams pr = (android.widget.FrameLayout.LayoutParams) content
.getLayoutParams();
pr.rightMargin = xOffset;
content.setLayoutParams(pr);
but it doesnt work, the margin appears but the content is not moved just resized to fit the screen, anyone know how to do this the simple way?
you can set the margin in negative(-) values.
for example if your want the layout to move upper use this:
android:marginTop = "-50dip or more u can put"
Are you trying to flip between views? As in, moving that layout off the screen to show another one? If so you should look at using a widget called ViewFlipper which will do exactly as you need. It can also be animated etc.
http://developer.android.com/reference/android/widget/ViewFlipper.html
I'm trying to make my own custom view, currently all it does is draw an image on a specific x and y coordinate and then draws the similar images repeatedly on different locations.
I want to be able to create a button on each instance of the image that is drawn. if one image is clicked it will have cause something different to happen depending on which image is chosen.
How can I implement this?
would I have to create a different view for each image/button combination and then set an onClick event?
Let me try to be a little more clear
I'm trying to make a map using hexagon (different types of terrains for different players)
I've figured out how to get them to draw (see here - they will have a border to show what terrain is owned by whom)
I just made a custom view class and had the hexagons drawn using a Canvas; however, I'm not sure how to be able to make the hexagons into buttons so that I can differentiate between which hexagon was chosen and how it should react to the opponents spot.
I was thinking of making a ViewGroup called Terrain to contain the Nodes(hexagons) that belong to the player and have a group of Node Views that only draw the hexagon where it should be located.
the question is can i make each node or the entire viewGroup into a button (or do an onTouch ) if a certain hexagon is pressed?
If I understood well, you should do :
One template my_pictures.xml which is a simple button.
Then you create a custom adapter which as a function for each kind of image you wanna create. By this, I mean that you will have to change the background value of your button depending on what you need it to be. Then you do a notifyDataSetChanged(); to refresh the container with the new button.
For the Listener, you just have to add it either in your activity or your adapter when you create your buttonImages, I don't know what's better.
Thanks for your help!
I figured out what I needed to do.
I have a NodeView class and in my GameActivity class, I'm using a relative layout and setting the layout parameters of where I wanted things positioned
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(95,95);
params.leftMargin = 10;
params.topMargin = 10;
params = new RelativeLayout.LayoutParams(95,95);
params.leftMargin = 10+95*x;
params.topMargin = 81+(71*y);
rl.addView(new NodeView (this,0,0,1,1), params);
This helped me add things where I needed them and now all I'm trying to figure out how to scroll around the territories on both the x and y axis (I tried ScrollView but that only allows me to scroll on the y-axis, I'm looking into it though)