English 中文(简体)
Touch () 内部布局不工作
原标题:Layout doesn t work inside onTouch()

我正在用两种图像观察来创建一项活动。

第一部《图像观察》在启动时占据了屏幕的一部分,我想展示另一部《图像观察》,其内容是围绕我触摸第一部《图像》以及其TOP的区域的作物。

类 :

public class DetectEyesActivity extends Activity  implements OnTouchListener {  
private ImageView imgView;
private Bitmap imgBitmap;

private ImageView touchView2;
private Bitmap temp;

@Override
public void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.detecteyeslayout);

    Intent intent = this.getIntent();
    byte[] image = intent.getByteArrayExtra("Image");

    imgView = (ImageView) findViewById(R.id.detectImageView1);
    touchView2 = (ImageView) findViewById(R.id.detectImageView2);

    imgBitmap = BitmapFactory.decodeByteArray(image, 0, image.length);
    imgView.setImageBitmap(imgBitmap);   

    temp = Bitmap.createBitmap(imgBitmap, 200, 200, 200, 200);
    //touchView2.setImageBitmap(temp);

    imgView.setOnTouchListener(this);
时 时

@Override
public boolean onTouch(View v, MotionEvent event) {
    int y = (int)event.getY();
    int x = (int)event.getX();

    temp = Bitmap.createBitmap(imgBitmap, 200,200, 200, 200);
    touchView2.setImageBitmap(temp);
    touchView2.setVisibility(0);
    touchView2.bringToFront();
    touchView2.layout(x-200, y-200, x-30, y-30);

    return true;
时 时

时 时

布局 :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/detectImageView1"
        android:layout_width="400dp"
        android:layout_height="400dp" />

    <ImageView
        android:id="@+id/detectImageView2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:visibility="gone" />
</LinearLayout>

但当我呼唤

touchView2.setImageBitmap(temp);

在 Touch () 上, 视图是在布局上初始图像下绘制的。 但是如果我在 Create () 上将其调用在初始图像上方?

为什么会发生这种事? 我怎样才能解决这个问题?

问题回答

据我理解您的问题, 您想要您的一个图像在另一个图像上覆盖。 线性Layout 以水平线或垂直线显示他们的孩子。 对于您的情况, 这不是一个好的观点组, 因为它不允许多个孩子占据相同的空间 。 我尝试一个相对版式或框架版式 。

另外,您还有第二个图像的可见度设置, 最初是 gone , 所以不是第一个图像被绘制在它上面, 而是第二个图像在您在您的 Touch 中调用 < code> set Visable 之前根本就没有被绘制过。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签