我怎么能够处理图像,然后在那里的功能? [英] how can i handle images and change there function?

查看:241
本文介绍了我怎么能够处理图像,然后在那里的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是很新的Andr​​oid和试图最近问这个问题,但没有人知道我在谈论,看着它自己的地狱我并不感到惊讶,(还挺更有意义,而我在写这什么),所以我已经改变了很多,希望能够让这个更清楚,在这里不用。
 单击时我想要实现的是一个图像,查看/按钮改变其观点和它的功能,
例如;当应用程序启动时,你获得2容器的顶部和底部,上方是空的,底部有3张图片,当你在底部容器点击其中3图像之一的所有变化和点击图像那张图像到顶层容器。

它将为此两次或三次填充不同组的图像进入底部容器每次一个被选择,而每个选择的图像添加到顶部容器旁边的最后

在此刻我的code完成这第一部分

在底部显示的3张图像,当我的应用程序启动前是空

当点击第一图像被放置在顶部和底部有新的图像

如果第二图像被从该应用点击启动该图像将在顶部和下面的图像将再次不同这样

和如果第三图像是从开始该图像将是在顶部的应用程式点击和图像下面将再次不同这样

现在我的问题是

,它将为此两次或三次填充不同组的图像进入底部容器每次一个被选择,而每个选择的图像添加到顶部容器旁边的最后。

香港专业教育学院尝试了关于这个没有太多的欢乐几家不同的方法,但不能看到的方式,我可以改变图像的有功能(最可能是由于缺乏经验)的ID或,但现在我在想,我可能会再次使用使用的getId和SETID任何人可以借我有两分钱这个也许有更好的方式GridView和图像阵列改写,这里是我的code

 包com.martinsapp.socialstories;进口android.app.Activity;
进口android.content.Intent;
进口android.view.View;
进口android.os.Bundle;
进口android.widget.ImageButton;
公共类speakActivity延伸活动{INT讲= 1;
的ImageButton BTN1;
的ImageButton BTN2;
的ImageButton btn3;
的ImageButton btn4;
的ImageButton btn5;
的ImageButton btn6;的ImageButton btnmt1;
的ImageButton btnmt2;
的ImageButton btnmt3;
的ImageButton btnmt4;
的ImageButton btnmt5;
的ImageButton btnmt6;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_speak);        BTN1 =(的ImageButton)findViewById(R.id.imageButton);
        btn1.setOnClickListener(ButtonClickListener);
        btn1.setBackgroundColor(View.INVISIBLE);
        BTN2 =(的ImageButton)findViewById(R.id.imageButton2);
        btn2.setOnClickListener(ButtonClickListener);
        btn2.setBackgroundColor(View.INVISIBLE);
        btn3 =(的ImageButton)findViewById(R.id.imageButton3);
        btn3.setOnClickListener(ButtonClickListener);
        btn3.setBackgroundColor(View.INVISIBLE);
        btn4 =(的ImageButton)findViewById(R.id.imageButton4);
        btn4.setOnClickListener(ButtonClickListener);
        btn4.setBackgroundColor(View.INVISIBLE);
        btn5 =(的ImageButton)findViewById(R.id.imageButton5);
        btn5.setOnClickListener(ButtonClickListener);
        btn5.setBackgroundColor(View.INVISIBLE);
        btn6 =(的ImageButton)findViewById(R.id.imageButton6);
        btn6.setOnClickListener(ButtonClickListener);
        btn6.setBackgroundColor(View.INVISIBLE);        btnmt1 =(的ImageButton)findViewById(R.id.imageButtonempty1);
        btnmt1.setOnClickListener(ButtonClickListener);
        btnmt1.setVisibility(View.INVISIBLE);
        btnmt2 =(的ImageButton)findViewById(R.id.imageButtonempty2);
        btnmt2.setOnClickListener(ButtonClickListener);
        btnmt2.setVisibility(View.INVISIBLE);
        btnmt3 =(的ImageButton)findViewById(R.id.imageButtonempty3);
        btnmt3.setOnClickListener(ButtonClickListener);
        btnmt3.setVisibility(View.INVISIBLE);
        btnmt4 =(的ImageButton)findViewById(R.id.imageButtonempty4);
        btnmt4.setOnClickListener(ButtonClickListener);
        btnmt4.setVisibility(View.INVISIBLE);
        btnmt5 =(的ImageButton)findViewById(R.id.imageButtonempty5);
        btnmt5.setOnClickListener(ButtonClickListener);
        btnmt5.setVisibility(View.INVISIBLE);
        btnmt6 =(的ImageButton)findViewById(R.id.imageButtonempty6);
        btnmt6.setOnClickListener(ButtonClickListener);
        btnmt6.setVisibility(View.INVISIBLE);        如果(说话== 1){
            btn1.setImageResource(R.drawable.i_want);            btn2.setImageResource(R.drawable.i_like);
            btn3.setImageResource(R.drawable.i_feel);
            btn4.setVisibility(View.INVISIBLE);
            btn5.setVisibility(View.INVISIBLE);
            btn6.setVisibility(View.INVISIBLE);
        }}
私人View.OnClickListener ButtonClickListener =新View.OnClickListener(){    @覆盖
    公共无效的onClick(视图v){
        开关(v.getId()){
            案例R.id.imageButton:
                说话= 2;
                如果(说话== 2){
                    btn1.setImageResource(R.drawable.to_play);
                    btn2.setImageResource(R.drawable.to_eat);
                    btn3.setImageResource(R.drawable.a_drink);
                    btn4.setImageResource(R.drawable.a_hug);
                    btn4.setVisibility(View.VISIBLE);
                    btn5.setVisibility(View.INVISIBLE);
                    btn6.setVisibility(View.INVISIBLE);                    btnmt1.setBackgroundResource(R.drawable.i_want);
                    btnmt1.setVisibility(View.VISIBLE);                }
                打破;            案例R.id.imageButton2:
                说话= 3;                如果(说话== 3){
                    btn1.setImageResource(R.drawable.friends);
                    btn2.setImageResource(R.drawable.music);
                    btn3.setImageResource(R.drawable.sports);
                    btn4.setImageResource(R.drawable.emptypuzzlepiece);
                    btn5.setImageResource(R.drawable.emptypuzzlepiece);
                    btn3.setVisibility(View.VISIBLE);
                    btn4.setVisibility(View.INVISIBLE);
                    btn5.setVisibility(View.INVISIBLE);
                    btn6.setVisibility(View.INVISIBLE);                    btnmt1.setBackgroundResource(R.drawable.i_like);
                    btnmt1.setVisibility(View.VISIBLE);
                }
                打破;
            案例R.id.imageButton3:
                说话= 4;
                如果(说话== 4){
                    btn1.setImageResource(R.drawable.sad);
                    btn2.setImageResource(R.drawable.happy);
                    btn3.setImageResource(R.drawable.sick);
                    btn4.setVisibility(View.INVISIBLE);
                    btn5.setVisibility(View.INVISIBLE);
                    btn6.setVisibility(View.INVISIBLE);                    btnmt1.setBackgroundResource(R.drawable.i_feel);
                    btnmt1.setVisibility(View.VISIBLE);                }
                }
}
};
}


解决方案

所以,你想改变绘制资源 R.drawable.i_feel 是一个不同的图像?结果
恐怕,这是不可能的。 Android为每个图像的可绘制文件夹的唯一标识。

如果有应该在底部容器上显示的图像的特定集合,你需要创建每一组数组。

我建议你改变OnClickListener一点。
你可以把它变成这样:

 私人View.OnClickListener ButtonClickListener =新View.OnClickListener(){@覆盖
公共无效的onClick(视图v){
    的ImageButton clickedButton =(ImageButton的)V;
    可绘制latestDrawable = clickedButton.getDrawable();
    开关(v.getId()){
        案例R.id.imageButton:
            说话= 2;
            如果(说话== 2){
                btn1.setImageResource(R.drawable.to_play);
                btn2.setImageResource(R.drawable.to_eat);
                btn3.setImageResource(R.drawable.a_drink);
                btn4.setImageResource(R.drawable.a_hug);
                setImageButtonVisibilities();                btnmt1.setImageDrawable(latestDrawable);
                btnmt1.setVisibility(View.VISIBLE);
            }
            打破;        案例R.id.imageButton2:
            说话= 3;
            如果(说话== 3){
                btn1.setImageResource(R.drawable.friends);
                btn2.setImageResource(R.drawable.music);
                btn3.setImageResource(R.drawable.sports);
                btn4.setImageResource(R.drawable.emptypuzzlepiece);
                btn5.setImageResource(R.drawable.emptypuzzlepiece);
                setImageButtonVisibilities();                btnmt1.setImageDrawable(latestDrawable);
                btnmt1.setVisibility(View.VISIBLE);
            }
            打破;
        案例R.id.imageButton3:
            说话= 4;
            如果(说话== 4){
                btn1.setImageResource(R.drawable.sad);
                btn2.setImageResource(R.drawable.happy);
                btn3.setImageResource(R.drawable.sick);
                setImageButtonVisibilities();                btnmt1.setImageDrawable(latestDrawable);
                btnmt1.setVisibility(View.VISIBLE);
            }
    }
}私人setImageButtonVisibilities(){
    如果(btn1.getDrawable == NULL)
        btn1.setVisibility(View.INVISIBLE);
    其他
        btn1.setVisibility(View.VISIBLE);
    如果(btn2.getDrawable == NULL)
        btn2.setVisibility(View.INVISIBLE);
    其他
        btn2.setVisibility(View.VISIBLE);
    如果(btn3.getDrawable == NULL)
        btn3.setVisibility(View.INVISIBLE);
    其他
        btn3.setVisibility(View.VISIBLE);
    如果(btn4.getDrawable == NULL)
        btn4.setVisibility(View.INVISIBLE);
    其他
        btn4.setVisibility(View.VISIBLE);
    如果(btn5.getDrawable == NULL)
        btn5.setVisibility(View.INVISIBLE);
    其他
        btn5.setVisibility(View.VISIBLE);
    如果(btn6.getDrawable == NULL)
        btn6.setVisibility(View.INVISIBLE);
    其他
        btn6.setVisibility(View.VISIBLE);
}
}

这将始终把的可绘制 pssed的$ P $ 的ImageButton 作为绘制对象的ImageButton的在顶部容器。结果
新的方法只是你在任何情况语句做能见度变化帮助。结果你需要每次调用它,你改变了可绘制。你为cn复制和在类粘贴,以及...

我希望这可以帮助你一点。

Hi i'm very new to android and tried to ask this question recently, but nobody understood what the hell i was talking about and looking at it myself i'm not surprised, (kinda made more sense while i was writing it) so I've changed a lot to hopefully make this much clearer, here goes. What i want to achieve is an image, view/button that changes its view and its function when clicked, For example; when the app starts you get 2 containers top and bottom, the top is empty and the bottom has 3 images, when you click on one of these 3 images in the bottom container the images all change and the clicked image goes into the top container.

it will do this two or three times populating different sets of images into the bottom container each time one is selected, whilst adding each selected image into the top container next to the last.

my code at the moment accomplishes the first part of this

3 images displayed at the bottom when my app starts the top is empty

when the first image is clicked it is put in the top and there are new images in the bottom

if the second image was clicked from the app starting that image would be in the top and the images below would be different again like this

and if the third image was clicked from the app starting that image would be in the top and the images below would be different again like this

Now my problem is

"it will do this two or three times populating different sets of images into the bottom container each time one is selected, whilst adding each selected image into the top container next to the last."

ive tried a few different approaches with regards to this without much joy but cant see a way that i can change the ids of the the images or there function (most probably due to a lack of experience) but i am now thinking that i may rewrite it again using a gridView and image arrays using getId and setId can anybody lend me there two cents on this maybe there is a better way, here is my code

package com.martinsapp.socialstories;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.os.Bundle;
import android.widget.ImageButton;


public class speakActivity extends Activity{

int speak = 1;
ImageButton btn1;
ImageButton btn2;
ImageButton btn3;
ImageButton btn4;
ImageButton btn5;
ImageButton btn6;

ImageButton btnmt1;
ImageButton btnmt2;
ImageButton btnmt3;
ImageButton btnmt4;
ImageButton btnmt5;
ImageButton btnmt6;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_speak);

        btn1 = (ImageButton)findViewById(R.id.imageButton);
        btn1.setOnClickListener(ButtonClickListener);
        btn1.setBackgroundColor(View.INVISIBLE);
        btn2 = (ImageButton)findViewById(R.id.imageButton2);
        btn2.setOnClickListener(ButtonClickListener);
        btn2.setBackgroundColor(View.INVISIBLE);
        btn3 = (ImageButton)findViewById(R.id.imageButton3);
        btn3.setOnClickListener(ButtonClickListener);
        btn3.setBackgroundColor(View.INVISIBLE);
        btn4 = (ImageButton)findViewById(R.id.imageButton4);
        btn4.setOnClickListener(ButtonClickListener);
        btn4.setBackgroundColor(View.INVISIBLE);
        btn5 = (ImageButton)findViewById(R.id.imageButton5);
        btn5.setOnClickListener(ButtonClickListener);
        btn5.setBackgroundColor(View.INVISIBLE);
        btn6 = (ImageButton)findViewById(R.id.imageButton6);
        btn6.setOnClickListener(ButtonClickListener);
        btn6.setBackgroundColor(View.INVISIBLE);

        btnmt1 = (ImageButton)findViewById(R.id.imageButtonempty1);
        btnmt1.setOnClickListener(ButtonClickListener);
        btnmt1.setVisibility(View.INVISIBLE);
        btnmt2 = (ImageButton)findViewById(R.id.imageButtonempty2);
        btnmt2.setOnClickListener(ButtonClickListener);
        btnmt2.setVisibility(View.INVISIBLE);
        btnmt3 = (ImageButton)findViewById(R.id.imageButtonempty3);
        btnmt3.setOnClickListener(ButtonClickListener);
        btnmt3.setVisibility(View.INVISIBLE);
        btnmt4 = (ImageButton)findViewById(R.id.imageButtonempty4);
        btnmt4.setOnClickListener(ButtonClickListener);
        btnmt4.setVisibility(View.INVISIBLE);
        btnmt5 = (ImageButton)findViewById(R.id.imageButtonempty5);
        btnmt5.setOnClickListener(ButtonClickListener);
        btnmt5.setVisibility(View.INVISIBLE);
        btnmt6 = (ImageButton)findViewById(R.id.imageButtonempty6);
        btnmt6.setOnClickListener(ButtonClickListener);
        btnmt6.setVisibility(View.INVISIBLE);

        if (speak == 1){
            btn1.setImageResource(R.drawable.i_want);

            btn2.setImageResource(R.drawable.i_like);
            btn3.setImageResource(R.drawable.i_feel);
            btn4.setVisibility(View.INVISIBLE);
            btn5.setVisibility(View.INVISIBLE);
            btn6.setVisibility(View.INVISIBLE);
        }

}
private View.OnClickListener ButtonClickListener = new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        switch(v.getId()) {
            case R.id.imageButton:
                speak = 2;
                if (speak == 2){
                    btn1.setImageResource(R.drawable.to_play);
                    btn2.setImageResource(R.drawable.to_eat);
                    btn3.setImageResource(R.drawable.a_drink);
                    btn4.setImageResource(R.drawable.a_hug);
                    btn4.setVisibility(View.VISIBLE);
                    btn5.setVisibility(View.INVISIBLE);
                    btn6.setVisibility(View.INVISIBLE);

                    btnmt1.setBackgroundResource(R.drawable.i_want);
                    btnmt1.setVisibility(View.VISIBLE);



                }
                break;

            case R.id.imageButton2:
                speak = 3;

                if (speak == 3){
                    btn1.setImageResource(R.drawable.friends);
                    btn2.setImageResource(R.drawable.music);
                    btn3.setImageResource(R.drawable.sports);
                    btn4.setImageResource(R.drawable.emptypuzzlepiece);
                    btn5.setImageResource(R.drawable.emptypuzzlepiece);
                    btn3.setVisibility(View.VISIBLE);
                    btn4.setVisibility(View.INVISIBLE);
                    btn5.setVisibility(View.INVISIBLE);
                    btn6.setVisibility(View.INVISIBLE);

                    btnmt1.setBackgroundResource(R.drawable.i_like);
                    btnmt1.setVisibility(View.VISIBLE);
                }


                break;
            case R.id.imageButton3:
                speak = 4;
                if (speak == 4){
                    btn1.setImageResource(R.drawable.sad);
                    btn2.setImageResource(R.drawable.happy);
                    btn3.setImageResource(R.drawable.sick);
                    btn4.setVisibility(View.INVISIBLE);
                    btn5.setVisibility(View.INVISIBLE);
                    btn6.setVisibility(View.INVISIBLE);

                    btnmt1.setBackgroundResource(R.drawable.i_feel);
                    btnmt1.setVisibility(View.VISIBLE);

                }


                }


}
};
}

解决方案

So you want to change the drawable Resource R.drawable.i_feel to be a different image?
I'm afraid, that's not possible. Android gives every image in the drawables folder a unique Id.

If there should be specific sets of images been shown in the bottom container, you'll need to create an array for every set.

I'd recommend you to change the OnClickListener a bit. You can change it into this:

private View.OnClickListener ButtonClickListener = new View.OnClickListener() {

@Override
public void onClick(View v) {
    ImageButton clickedButton = (ImageButton) v;
    Drawable latestDrawable = clickedButton.getDrawable();
    switch (v.getId()) {
        case R.id.imageButton:
            speak = 2;
            if (speak == 2) {
                btn1.setImageResource(R.drawable.to_play);
                btn2.setImageResource(R.drawable.to_eat);
                btn3.setImageResource(R.drawable.a_drink);
                btn4.setImageResource(R.drawable.a_hug);
                setImageButtonVisibilities();

                btnmt1.setImageDrawable(latestDrawable);
                btnmt1.setVisibility(View.VISIBLE);
            }
            break;

        case R.id.imageButton2:
            speak = 3;
            if (speak == 3) {
                btn1.setImageResource(R.drawable.friends);
                btn2.setImageResource(R.drawable.music);
                btn3.setImageResource(R.drawable.sports);
                btn4.setImageResource(R.drawable.emptypuzzlepiece);
                btn5.setImageResource(R.drawable.emptypuzzlepiece);
                setImageButtonVisibilities();

                btnmt1.setImageDrawable(latestDrawable);
                btnmt1.setVisibility(View.VISIBLE);
            }
            break;
        case R.id.imageButton3:
            speak = 4;
            if (speak == 4) {
                btn1.setImageResource(R.drawable.sad);
                btn2.setImageResource(R.drawable.happy);
                btn3.setImageResource(R.drawable.sick);
                setImageButtonVisibilities();

                btnmt1.setImageDrawable(latestDrawable);
                btnmt1.setVisibility(View.VISIBLE);
            }
    }
}

private setImageButtonVisibilities() {
    if(btn1.getDrawable == null)
        btn1.setVisibility(View.INVISIBLE);
    else
        btn1.setVisibility(View.VISIBLE);
    if(btn2.getDrawable == null)
        btn2.setVisibility(View.INVISIBLE);
    else
        btn2.setVisibility(View.VISIBLE);
    if(btn3.getDrawable == null)
        btn3.setVisibility(View.INVISIBLE);
    else
        btn3.setVisibility(View.VISIBLE);
    if(btn4.getDrawable == null)
        btn4.setVisibility(View.INVISIBLE);
    else
        btn4.setVisibility(View.VISIBLE);
    if(btn5.getDrawable == null)
        btn5.setVisibility(View.INVISIBLE);
    else
        btn5.setVisibility(View.VISIBLE);
    if(btn6.getDrawable == null)
        btn6.setVisibility(View.INVISIBLE);
    else
        btn6.setVisibility(View.VISIBLE);
}
}

This will always put the Drawable of the pressed ImageButton as Drawable for the ImageButton in the top container.
The new method is just helping with the Visibility changes you do in any case statement.
You'll need to call it everytime you changed the Drawables. you cn copy and paste it in in the class as well...

I hope this helps you a bit.

这篇关于我怎么能够处理图像,然后在那里的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆