Im working on changing the image being shown when I have my ImageView Clicked. Im trying to use a similar code that I used for accomplishing this with a TextView but I can't seem to find the right terms to get it to work. Here is my current code. Thanks
electronconfiguration.setOnClickListener(new View.OnClickListener() {
public void onClick(View drawable) {
if (drawable.equals(R.drawable.element_el))
electronconfiguration.setImageDrawable(R.drawable.aluminum_el);
else if (drawable.equals(R.drawable.aluminum_el))
electronconfiguration.setImageDrawable(R.drawable.element_el);
}
});
Why don't you use a ViewSwitcher, it's designed to switch between two views
drawable probably doesn't equal R.drawable.element_el. R.drawable.element_el is probably some random implementation of the image. Try drawable.getId().equals(R.drawable.element_el). I've never tried this so I have no idea
Related
I am looking for a solution to test the touch screen of the android device like Amazon/Flipkart etc. do.
Can I get any working reference link which does a similar functionality?
Have you tried ScratchView? It seems very easy to integrate for ImageView and Textview both.
You may also check on this tutorial.
In addition, if you would like to create your own solution, you may place a view on top of ImageView and erase the Bitmap on touch with approach as mentioned in this StackOverflow answer.
Use this library
compile 'com.github.cooltechworks:ScratchView:v1.1'
Use the scratchable view in your xml
<com.cooltechworks.views.ScratchImageView
android:id="#+id/sample_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:src="#drawable/img_sample2"
/>
Add the listener for your scratch view like below and check for the percentage
scratchImageView.setRevealListener(new ScratchImageView.IRevealListener() {
#Override
public void onRevealed(ScratchImageView tv) {
// on reveal
}
#Override
public void onRevealPercentChangedListener(ScratchImageView siv, float percent) {
// if the percent is 1, then whole portion is scratched
}
});
For more info https://github.com/sharish/ScratchView
I guess this is pretty simple question but somehow I cannot figure it out.
I am animating couple of .png file from drawable folder, it is working fine as they are animated and stopped as required. What I am trying from previous three hours is that I want to hide the imageview once the animation is stopped. This is the simple code i am using
animImageView = (ImageView) findViewById(R.id.iv_animation);
animImageView.setBackgroundResource(R.drawable.anim);
animImageView.post(new Runnable() {
#Override
public void run() {
visiblity = false;
frameAnimation =
(AnimationDrawable) animImageView.getBackground();
frameAnimation.start();
frameAnimation.setOneShot(true);
//animImageView.setVisibility(View.INVISIBLE);
}
});
Even tried the removeCallBack() methods on imageview but its not working. Can somebody please guide me what I am doing wrong or what I need to do to overcome this.
Thanks.
There is no finish listener for AnimationDrawable. Try this approach, https://stackoverflow.com/a/15856260/1972597
What you can do is after your animation is over, just call
iv.setVisibility(View.GONE);
there is an animation listener availale. So you can use it for Animation Utils
I'm a bit new to Android, therefore question may sound ridiculous, but:
Is there any way to make a button in form of smthg? There ate tons of apps, where you press on a tree or some house and some action starts. How is that made?
Not action, but form. Or there is no way to make button NOT rectangular?
You are talking about imagebutton.Image button documentation
For example creating a button with tree background.Example:
<ImageButton android:src="#drawable/tree.png"></ImageButton>
Yes you can do that. Considering your trees and house as an image.
ImageView im;
im = (ImageView) findViewById(R.id.image_of_tree);
im.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//perform some action
}
});
Off-course When you get inflated your layout and your view(can be any view) is available by id. your button can be an ImageView, ImageButton etc. just find the id for your view and set whatever event you want to listen by this view.
I apologize for this, and I am sure it's a very rookie question... but I am still trying to grasp java and how everything works (I'm surprised I made it this far.)
I have a TextView inside of a ScrollView and I am trying to get it to focus on the bottom entry each time a new entry is added.
I have this in the code:
getScrollView().post (new Runnable() {
#Override
public void run() {
getScrollView().fullScroll(ScrollView.FOCUS_DOWN);
}
});
that is inside the
public void onClick(View src) {
switch(src.getId()){
case R.id.buttonOk:
(So that when I click ok, it will focus to the bottom.)
now.. I am getting this error: The method getScrollView() is undefined for the type
do i need to call out the name of the scroll view within that first set of code, android:id="#+id/scrollView1"
Again, I am sorry I am so confused on this. I am obviously not getting something right here. Any help is greatly appreciated.
Thanks
you can used this.
scrollview=((ScrollView) findViewById(R.id.scrollview));
scrollview.post(new Runnable() {
#Override
public void run() {
scrollview.fullScroll(ScrollView.FOCUS_DOWN);
}
});
A couple things:
To get access to the view from code, you use (ScrollView)findViewById(R.id.scrollView1) -- getScrollView() doesn't exist, though you can write it using the command I described.
Based on what it sounds like you're trying to do, you might want to look into ListView instead (rather than appending lines to a TextView).
I am developing a simple application ,in that there is set of 6 buttons.
when i clicked on one of these button then the other buttons must be partially transparent. I tried to done that By setting alpha of 5 buttons
acre_button.getBackground().mutate().setAlpha(155);
Ui of the application not changed as i expected. i got only 3 out of 5 is get transparent.when clicking on that two button it is slowly changing it's transparency
Thanks in advance
regards,
kariyachan
Button btn;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.main_btn);
Drawable d = getResources().getDrawable(R.drawable.imagen);
d.setAlpha(60);
btn.setBackgroundDrawable(d);
}
This works for me :)
Find a button background in your android-sdk directory here: android-sdk\platforms\android-10\data\res\drawable-mdpi\btn_default_normal.9.png
You can modify it to make it semi transparent (Please note that this is a 9-patch and you shouldn't change the opacity of the black lines).
Once you have this changed button in your drawable directory you can add this to your code:
button.setBackgroundDrawable(getResources().getDrawable(R.drawable.transparentImage));
to make it semi transparent and
button.setBackgroundDrawable(getResources().getDrawable(Android.R.drawable.btn_default_normal));
to change it back.
For anyone still hunting for a solution to this:
The method setBackgroundDrawable(Drawable d) is deprecated as of API 16
Assuming your button's id is buttonId and your drawable is named button_img,
handle this by using the following within the onCreate method:
((Button)(findViewById(R.id.buttonId))).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Drawable d = v.getResources().getDrawable(R.drawable.button_img);
d.setAlpha(40);
if (Build.VERSION.SDK_INT >= 16)
v.setBackground(d);
else
v.setBackgroundDrawable(d);
//Then call your next Intent or desired action.
}
});
Tested and works for me!
Try the following:
button.setBackgroundColor(android.R.color.transparent);