Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将两个图像视图中的一个设置为透明/不可见,显示白色屏幕_Android_Imageview_Visibility_Transparent - Fatal编程技术网

Android 将两个图像视图中的一个设置为透明/不可见,显示白色屏幕

Android 将两个图像视图中的一个设置为透明/不可见,显示白色屏幕,android,imageview,visibility,transparent,Android,Imageview,Visibility,Transparent,我是一个新手,已经为此工作了几天,但没有任何成功。如果有人帮忙,我们将不胜感激 我有两个ImageView,一个在活动中,一个在另一个后面。我想使第一个(顶部的那个)不可见或透明,这样我就可以在代码内部使用它。第二个(底部的那个)应该保持可见,以便用户可以与之交互。我尝试先将画布设置为透明,然后设置顶部的ImageVIew,这会导致屏幕显示白色,而不是在后面显示ImageVIew(底部的)。谁能解释一下为什么会发生这种情况,并给我一个更好的方法来实现我的目标?提前谢谢 以下是我的.java代码:

我是一个新手,已经为此工作了几天,但没有任何成功。如果有人帮忙,我们将不胜感激

我有两个ImageView,一个在活动中,一个在另一个后面。我想使第一个(顶部的那个)不可见或透明,这样我就可以在代码内部使用它。第二个(底部的那个)应该保持可见,以便用户可以与之交互。我尝试先将画布设置为透明,然后设置顶部的ImageVIew,这会导致屏幕显示白色,而不是在后面显示ImageVIew(底部的)。谁能解释一下为什么会发生这种情况,并给我一个更好的方法来实现我的目标?提前谢谢

以下是我的.java代码:

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final ImageView imageView = (ImageView) findViewById(R.id.imageView1);
        imageView.setVisibility(View.INVISIBLE);

        imageView.setOnTouchListener(new ImageView.OnTouchListener(){
            public boolean onTouch(View v, MotionEvent event) {
                if(event.getAction() == MotionEvent.ACTION_DOWN) {
                    Drawable imgDrawable = ((ImageView)imageView).getDrawable();
                    Bitmap mutableBitmap = Bitmap.createBitmap(imageView.getWidth(), imageView.getHeight(), Bitmap.Config.ARGB_8888);
                    Canvas canvas = new Canvas(mutableBitmap);
                    imgDrawable.draw(canvas);
                    int pixel = mutableBitmap.getPixel((int)event.getX(), (int)event.getY());
                    Log.i("PIXEL COLOR", ""+pixel);

                    int alpha = Color.alpha(pixel);
                    int red = Color.red(pixel);
                    int blue = Color.blue(pixel);
                    int green = Color.green(pixel);
                    String color = String.format("#%02X%02X%02X%02X", alpha, red, green, blue);
                    Log.i("RGB", color);

                    float[] hsv = new float[3];
                    Color.RGBToHSV(red, green, blue, hsv);
                    Log.i("HSV_H", "Hue=" + hsv[0]);
                    Log.i("HSV_H", "Saturation=" + hsv[1]);
                    Log.i("HSV_H", "Value=" + hsv[2]);
               }
               return true;
            }
        });
}
}

以下是我的.xml代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:src="@drawable/lapices" />

   <ImageView
        android:id="@+id/imageView2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:src="@drawable/lapices" />

</LinearLayout>

我真的看不出你想要实现什么。 它应该存在一个更好的方式,但据我所知,如果你在相对论中改变线性布局,改变图像视图的顺序,它应该会工作

顺便说一下,一些代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 <ImageView
        android:id="@+id/imageView2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:visibility="invisible"
        android:src="@drawable/ic_action_search" />


</RelativeLayout>

非常感谢用户2122876的回复,非常感谢。我想使用两个Imageview层,一个在另一个的顶部,并从顶部获得用户交互,不可见的一个,但我不知道如何在Android中做到这一点,因为不可见的Imageview似乎不接受用户交互。还是有办法做到这一点?再次感谢您抽出时间。