gpt4 book ai didi

android - ImageView 显示上一个 ImageView 的数据

转载 作者:行者123 更新时间:2023-11-29 21:47:18 27 4
gpt4 key购买 nike

我有以下看法: enter image description here

如果我点击任何 ImageButton 以全屏模式显示相应的图像。例如,如果我点击 Black ,它会显示 ImageView ,如:enter image description here

我还为一些图像按钮将背景设置为全屏颜色:如果我单击粉红色,它会显示纯粉红色:

enter image description here

到此为止一切正常,如果我先点击黑色按钮,然后点击粉色,黑色上的图像会被带到粉红色背景的布局上,就像这样:

enter image description here

这是我的问题,我只想要粉红色,而不是前景中的图像;

这是我的 XML 文件:

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#657383" >

<ImageView android:id="@+id/imv"
android:contentDescription="@string/app_name"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
/>

<Button android:id="@+id/home"
android:contentDescription="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="@string/Back_Button"
android:textSize="25sp"
/>


<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">


<ImageButton android:id="@+id/image1"
android:contentDescription="@string/hello_world"
android:layout_width="130dp"
android:layout_height="95dp"
android:background="#000000"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"/>

<ImageButton android:id="@+id/image2"
android:contentDescription="@string/hello_world"
android:layout_width="130dp"
android:layout_height="95dp"
android:layout_toRightOf="@+id/image1"
android:background="#ff0000"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"/>

<ImageButton android:id="@+id/image3"
android:contentDescription="@string/hello_world"
android:layout_width="130dp"
android:layout_height="95dp"
android:layout_below="@+id/image1"
android:background="#00ff00"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
/>

<ImageButton android:id="@+id/image4"
android:contentDescription="@string/hello_world"
android:layout_width="130dp"
android:layout_height="95dp"
android:background="#0000ff"
android:layout_below="@+id/image2"
android:layout_toRightOf="@+id/image3"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
/>

<ImageButton android:id="@+id/image5"
android:contentDescription="@string/hello_world"
android:layout_width="130dp"
android:layout_height="95dp"
android:background="#FFFF00"
android:layout_below="@+id/image3"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
/>

<ImageButton android:id="@+id/image6"
android:contentDescription="@string/hello_world"
android:layout_width="130dp"
android:layout_height="95dp"
android:layout_below="@+id/image4"
android:layout_toRightOf="@+id/image5"
android:background="#FFA500"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"/>

<ImageButton android:id="@+id/image7"
android:contentDescription="@string/hello_world"
android:layout_width="130dp"
android:layout_height="95dp"
android:layout_below="@+id/image5"
android:background="#FFFFFF"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"/>

<ImageButton android:id="@+id/image8"
android:contentDescription="@string/hello_world"
android:layout_width="130dp"
android:layout_height="95dp"
android:layout_below="@+id/image6"
android:background="#F52887"
android:layout_toRightOf="@+id/image7"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"/>



</RelativeLayout>

我的 .Java 数据是:

      private OnClickListener myListener = new OnClickListener() {

@SuppressLint("NewApi")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub


try {

handler.postDelayed(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
iv.setVisibility(View.GONE);
}
}, 2500);



if (v.getId() == R.id.image1) {
iv.setBackground(null);
iv.setVisibility(View.VISIBLE);
iv.setImageResource(R.drawable.ic_launcher);

} else if(v.getId() == R.id.image2){
iv.setBackground(null);

iv.setVisibility(View.VISIBLE);
iv.setImageResource(R.drawable.kids_paint_hands);
}else if(v.getId() == R.id.image3){

iv.setBackground(null);

iv.setVisibility(View.VISIBLE);
iv.setImageResource(R.drawable.play_logo);
}else if(v.getId() == R.id.image4){

iv.setBackground(null);
iv.setVisibility(View.VISIBLE);
iv.setBackgroundColor(Color.BLUE);
}else if(v.getId() == R.id.image5){

iv.setBackground(null);

iv.setVisibility(View.VISIBLE);
iv.setBackgroundColor(Color.CYAN);
}else if(v.getId() == R.id.image6){

iv.setBackground(null);

iv.setVisibility(View.VISIBLE);
iv.setBackgroundColor(Color.MAGENTA);
}else if(v.getId() == R.id.image7){

iv.setBackground(null);

iv.setVisibility(View.VISIBLE);
iv.setBackgroundColor(Color.WHITE);
}else if(v.getId() == R.id.image8){

iv.setBackground(null);

iv.setVisibility(View.VISIBLE);
iv.setBackgroundColor(Color.DKGRAY);
iv.clearFocus();
}






} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}

任何帮助或建议?

最佳答案

试试这个

首先

ImageResource is different from the background Resource.

ImageResource is the foreground image, background resource is the background one.

你需要这样做

image.setImageResource(android.R.color.transparent);

显示透明图像而不是原始图像

关于android - ImageView 显示上一个 ImageView 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15447180/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com