获取按钮坐标和检测,如果手指是在他们 - 机器人 [英] Get button coordinates and detect if finger is over them - Android

查看:128
本文介绍了获取按钮坐标和检测,如果手指是在他们 - 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Andr​​oid应用程序活动的4个按钮。这是它的样子:

正如你所看到的,textViews在屏幕的底部显示x和y坐标。坐标是在参照的相对布局。 (请参见下面给出code)

现在,我想要做的就是的4个按钮的X和Y坐标,在运行时,然后计算出如果我的手指触摸按键,同时移动或没有。在简单的话,我想preSS按钮刷卡我的手指在他们,而不是提升和感人。我怎样才能实现呢?我想在我的钢琴应用程序中实现它。

我能得到在屏幕上的坐标,他们改变,因为我将我的手指。
所以,我的问题是我怎样才能获得按钮的坐标,并检测是否我的手指轻扫在他们之上:?
XML

 < RelativeLayout的
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:后台=#FFFFFF
机器人:ID =@ + ID / RelativeLayout的>

<的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:textAppearance =机器人:ATTR / textAppearanceMedium
    机器人:文本=Y线
    机器人:layout_marginLeft =10dp
    机器人:layout_marginBottom =10dp
    机器人:ID =@ + ID / TextView的
    机器人:layout_alignParentBottom =真
    机器人:layout_alignParentLeft =真/>

<的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:textAppearance =机器人:ATTR / textAppearanceMedium
    机器人:文本=X线
    机器人:layout_marginLeft =10dp
    机器人:layout_marginBottom =10dp
    机器人:ID =@ + ID / textView2
    机器人:layout_above =@ + ID / TextView的
    机器人:layout_alignParentLeft =真/>

<的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:textAppearance =机器人:ATTR / textAppearanceMedium
    机器人:ID =@ + ID / textView3
    机器人:文字颜色=#000000
    机器人:layout_below =@ + ID / textView2
    机器人:layout_toRightOf =@ + ID / TextView的/>

<的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:textAppearance =机器人:ATTR / textAppearanceMedium
    机器人:ID =@ + ID / textView4
    机器人:文字颜色=#000000
    机器人:layout_marginBottom =10dp
    机器人:layout_above =@ + ID / TextView的
    机器人:layout_toRightOf =@ + ID / TextView的/>

<按钮
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=新按钮
    机器人:ID =@ + ID /按钮
    机器人:文字颜色=#000000
    机器人:layout_alignParentTop =真
    机器人:layout_alignParentLeft =真
    机器人:layout_alignParentRight =真/>

<按钮
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=新按钮
    机器人:文字颜色=#000000
    机器人:ID =@ + ID /按钮2
    机器人:layout_below =@ + ID /按钮
    机器人:layout_alignParentLeft =真
    机器人:layout_alignParentRight =真/>

<按钮
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=新按钮
    机器人:文字颜色=#000000
    机器人:ID =@ + ID /按钮3
    机器人:layout_below =@ + ID /按钮2
    机器人:layout_alignParentLeft =真
    机器人:layout_alignParentRight =真/>

<按钮
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=新按钮
    机器人:ID =@ + ID /将Button4
    机器人:文字颜色=#000000
    机器人:layout_below =@ + ID /按钮3
    机器人:layout_alignParentLeft =真
    机器人:layout_alignParentRight =真/>

< / RelativeLayout的>
 

的Java

 公共类MainActivity延伸活动{

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
    最后的TextView xcordview =(TextView中)findViewById(R.id.textView4);
    最后的TextView ycordview =(TextView中)findViewById(R.id.textView3);
    RelativeLayout的的TouchView =(RelativeLayout的)findViewById(R.id.relativelayout);
    touchview.setOnTouchListener(新View.OnTouchListener(){
        @覆盖
        公共布尔onTouch(视图V,MotionEvent事件){
            xcordview.setText(将String.valueOf(event.getX()));
            ycordview.setText(将String.valueOf(event.getY()));
            返回true;
        }
    });

  }
}
 

感谢大家非常非常感谢!

更新:

 公共类MainActivity延伸活动{
RelativeLayout的的TouchView;
@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
    最后的TextView xcordview =(TextView中)findViewById(R.id.textView4);
    最后的TextView ycordview =(TextView中)findViewById(R.id.textView3);
    的TouchView =(RelativeLayout的)findViewById(R.id.relativelayout);
    touchview.setOnTouchListener(新View.OnTouchListener(){
        @覆盖
        公共布尔onTouch(视图V,MotionEvent事件){
            xcordview.setText(将String.valueOf(event.getX()));
            ycordview.setText(将String.valueOf(event.getY()));
            的for(int i = 0; I< touchview.getChildCount();我++){
                如果(checkInterSection(touchview.getChildAt(ⅰ),event.getRawX(),event.getRawY())){
                    Button按钮=(按钮)findViewById(R.id.button);
                    button.setBackgroundColor(Color.BLUE);
                    打破;
                }
            }
            返回true;
        }
    });

}
私人布尔checkInterSection(查看视图,浮rawX,浮rawY){
    INT []的位置=新INT [2];
    view.getLocationOnScreen(位置);
    INT X =位置[0];
    INT Y =位置[1];
    INT宽度= view.getWidth();
    INT高= view.getHeight();
    //检查点与矩形所取得的交集
    返程((rawX<!x || rawY> X +宽度|| rawY< Y || rawY> Y +高));
}

}
 

解决方案

 包com.example.touch;

进口android.app.Activity;
进口android.os.Bundle;
进口android.view.MotionEvent;
进口android.view.View;
进口android.widget.Button;
进口android.widget.RelativeLayout;
进口android.widget.TextView;

公共类MainActivity延伸活动{

    按钮B1,B2,B3,B4;

    INT b1x1,b1x2,b1y1,b1y2;

    私人TextView的xcordview;
    私人TextView的ycordview;
    私人TextView的buttonIndicator;
    私人RelativeLayout的的TouchView;
    私有静态诠释defaultStates [];
    私人按钮mLastButton;
    私人最终静态INT [] STATE_ preSSED = {
            android.R.attr.state_ pressed,
            android.R.attr.state_focused
                    | android.R.attr.state_enabled};

    @覆盖
    保护无效的onCreate(包savedInstanceState){

        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        xcordview =(TextView中)findViewById(R.id.textView4);
        ycordview =(TextView中)findViewById(R.id.textView3);
        buttonIndicator =(TextView中)findViewById(R.id.button_indicator);
        的TouchView =(RelativeLayout的)findViewById(R.id.relativelayout);

        B1 =(按钮)findViewById(R.id.button1);
        B2 =(按钮)findViewById(R.id.button2);
        B3 =(按钮)findViewById(R.id.button3);
        B4 =(按钮)findViewById(R.id.button4);
        defaultStates = b1.getBackground()的getState()。

    }

    @覆盖
    保护无效onResume(){
        // TODO自动生成方法存根
        super.onResume();

        touchview.setOnTouchListener(新View.OnTouchListener(){

            私人布尔isInside = FALSE;

            @覆盖
            公共布尔onTouch(视图V,MotionEvent事件){

                INT X =(int)的event.getX();
                INT Y =(INT)event.getY();

                xcordview.setText(将String.valueOf(X));
                ycordview.setText(将String.valueOf(Y));

                的for(int i = 0; I< touchview.getChildCount();我++){
                    视图电流= touchview.getChildAt(ⅰ);
                    如果(当前的instanceof按钮){
                        按钮B =(按钮)电流;

                        如果(!isPointWithin(X,Y,b.getLeft(),b.getRight(),b.getTop(),
                                b.getBottom())){
                            b.getBackground()的setState(defaultStates)。
                        }

                        如果(isPointWithin(X,Y,b.getLeft(),b.getRight(),b.getTop(),
                                b.getBottom())){
                            。b.getBackground()的setState(STATE_ preSSED);
                            如果(B!= mLastButton){
                                mLastButton = B;
                                buttonIndicator.setText(mLastButton.getText());
                            }
                        }

                    }
                }
                返回true;
            }

        });

    }

    @覆盖
    公共无效onWindowFocusChanged(布尔hasFocus){
        // TODO自动生成方法存根
        super.onWindowFocusChanged(hasFocus);
    }

    静态布尔isPointWithin(INT X,INT Y,INT X1,X2 INT,INT Y1,Y2 INT){
        则返回(x&其中; = X2&安培;&安培; X  -  GT; = X1&安培;&安培; Y&其中; = Y2&安培;&安培y与其所连接; = y1)上;
    }
}
 

布局文件

 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / RelativeLayout的
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:后台=#FFFFFF>

    <的TextView
        机器人:ID =@ + ID / TextView的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:layout_alignParentLeft =真
        机器人:layout_marginBottom =10dp
        机器人:layout_marginLeft =10dp
        机器人:文本=Y线
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium/>

    <的TextView
        机器人:ID =@ + ID / textView2
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_above =@ + ID / TextView的
        机器人:layout_alignParentLeft =真
        机器人:layout_marginBottom =10dp
        机器人:layout_marginLeft =10dp
        机器人:文本=X线
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium/>

    <的TextView
        机器人:ID =@ + ID / textView3
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ + ID / textView2
        机器人:layout_toRightOf =@ + ID / TextView的
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium
        机器人:文字颜色=#000000/>

    <的TextView
        机器人:ID =@ + ID / textView4
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_above =@ + ID / TextView的
        机器人:layout_marginBottom =10dp
        机器人:layout_toRightOf =@ + ID / TextView的
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium
        机器人:文字颜色=#000000/>

    <按钮
        机器人:ID =@ + ID /按钮1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentRight =真
        机器人:layout_alignParentTop =真
        机器人:文本=B1
        机器人:文字颜色=#000000/>

    <按钮
        机器人:ID =@ + ID /按钮2
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentRight =真
        机器人:layout_below =@ + ID /按钮1
        机器人:文本=B2
        机器人:文字颜色=#000000/>

    <按钮
        机器人:ID =@ + ID /按钮3
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentRight =真
        机器人:layout_below =@ + ID /按钮2
        机器人:文本=B3
        机器人:文字颜色=#000000/>

    <按钮
        机器人:ID =@ + ID /将Button4
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentRight =真
        机器人:layout_below =@ + ID /按钮3
        机器人:文本=B4
        机器人:文字颜色=#000000/>

    <的TextView
        机器人:ID =@ + ID / button_indicator
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentRight =真
        机器人:layout_alignTop =@ + ID / textView4
        机器人:layout_marginRight =33dp
        机器人:文本=没有人
        机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceLarge?

    <的TextView
        机器人:ID =@ + ID / textView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignBaseline =@ + ID / button_indicator
        机器人:layout_alignBottom =@ + ID / button_indicator
        机器人:layout_marginRight =29dp
        机器人:layout_toLeftOf =@ + ID / button_indicator
        机器人:文本=输入:
        机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceLarge?

< / RelativeLayout的>
 

I have 4 buttons in my android app activity. This is what it looks like:

As you can see, the textViews at the bottom of the screen display the x and y coordinates. The coordinates are in reference to a relative layout. (See below given code)

Now, what I want to do is get the x and y coordinates of the 4 buttons at runtime and then figure out if my finger is touching the buttons while moving or not. In simple words, I want to press the buttons by swiping my finger over them instead of lifting and touching. How can I achieve it? I want to implement it in my piano application.

I was able to get the coordinates on screen and they change as I move my finger.
So, my question is How can I get the coordinates of the buttons and detect if my finger is swiping above them?:
XML

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:id="@+id/relativelayout">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Y Cord : "
    android:layout_marginLeft="10dp"
    android:layout_marginBottom="10dp"
    android:id="@+id/textView"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="X Cord : "
    android:layout_marginLeft="10dp"
    android:layout_marginBottom="10dp"
    android:id="@+id/textView2"
    android:layout_above="@+id/textView"
    android:layout_alignParentLeft="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/textView3"
    android:textColor="#000000"
    android:layout_below="@+id/textView2"
    android:layout_toRightOf="@+id/textView" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/textView4"
    android:textColor="#000000"
    android:layout_marginBottom="10dp"
    android:layout_above="@+id/textView"
    android:layout_toRightOf="@+id/textView" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button"
    android:textColor="#000000"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:textColor="#000000"
    android:id="@+id/button2"
    android:layout_below="@+id/button"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:textColor="#000000"
    android:id="@+id/button3"
    android:layout_below="@+id/button2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button4"
    android:textColor="#000000"
    android:layout_below="@+id/button3"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true" />

</RelativeLayout>

Java

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final TextView xcordview = (TextView) findViewById(R.id.textView4);
    final TextView ycordview = (TextView) findViewById(R.id.textView3);
    RelativeLayout touchview = (RelativeLayout) findViewById(R.id.relativelayout);
    touchview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            xcordview.setText(String.valueOf(event.getX()));
            ycordview.setText(String.valueOf(event.getY()));
            return true;
        }
    });

  }
}

Thank you all very very much!

Update:

public class MainActivity extends Activity {
RelativeLayout touchview;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final TextView xcordview = (TextView) findViewById(R.id.textView4);
    final TextView ycordview = (TextView) findViewById(R.id.textView3);
    touchview = (RelativeLayout) findViewById(R.id.relativelayout);
    touchview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            xcordview.setText(String.valueOf(event.getX()));
            ycordview.setText(String.valueOf(event.getY()));
            for(int i = 0; i < touchview.getChildCount(); i++){
                if(checkInterSection(touchview.getChildAt(i), event.getRawX(), event.getRawY())){
                    Button button = (Button) findViewById(R.id.button);
                    button.setBackgroundColor(Color.BLUE);
                    break;
                }
            }
            return true;
        }
    });

}
private boolean checkInterSection(View view, float rawX, float rawY) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int x = location[0];
    int y = location[1];
    int width = view.getWidth();
    int height = view.getHeight();
    //Check the intersection of point with rectangle achieved
    return (!(rawX < x || rawY > x + width || rawY < y || rawY > y + height));
}

}

解决方案

package com.example.touch;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MainActivity extends Activity {

    Button b1, b2, b3, b4;

    int b1x1, b1x2, b1y1, b1y2;

    private TextView xcordview;
    private TextView ycordview;
    private TextView buttonIndicator;
    private RelativeLayout touchview;
    private static int defaultStates[];
    private Button mLastButton;
    private final static int[] STATE_PRESSED = {
            android.R.attr.state_pressed,
            android.R.attr.state_focused  
                    | android.R.attr.state_enabled };

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        xcordview = (TextView) findViewById(R.id.textView4);
        ycordview = (TextView) findViewById(R.id.textView3);
        buttonIndicator = (TextView) findViewById(R.id.button_indicator);
        touchview = (RelativeLayout) findViewById(R.id.relativelayout);

        b1 = (Button) findViewById(R.id.button1);
        b2 = (Button) findViewById(R.id.button2);
        b3 = (Button) findViewById(R.id.button3);
        b4 = (Button) findViewById(R.id.button4);
        defaultStates = b1.getBackground().getState();

    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

        touchview.setOnTouchListener(new View.OnTouchListener() {

            private boolean isInside = false;

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                int x = (int) event.getX();
                int y = (int) event.getY();

                xcordview.setText(String.valueOf(x));
                ycordview.setText(String.valueOf(y));

                for (int i = 0; i < touchview.getChildCount(); i++) {
                    View current = touchview.getChildAt(i);
                    if (current instanceof Button) {
                        Button b = (Button) current;

                        if (!isPointWithin(x, y, b.getLeft(), b.getRight(), b.getTop(),
                                b.getBottom())) {
                            b.getBackground().setState(defaultStates);
                        }

                        if (isPointWithin(x, y, b.getLeft(), b.getRight(), b.getTop(),
                                b.getBottom())) {
                            b.getBackground().setState(STATE_PRESSED);
                            if (b != mLastButton) {
                                mLastButton = b;
                                buttonIndicator.setText(mLastButton.getText());
                            }
                        }

                    }
                }
                return true;
            }

        });

    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        // TODO Auto-generated method stub
        super.onWindowFocusChanged(hasFocus);
    }

    static boolean isPointWithin(int x, int y, int x1, int x2, int y1, int y2) {
        return (x <= x2 && x >= x1 && y <= y2 && y >= y1);
    }
}

layout file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:text="Y Cord : "
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:text="X Cord : "
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView2"
        android:layout_toRightOf="@+id/textView"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView"
        android:layout_marginBottom="10dp"
        android:layout_toRightOf="@+id/textView"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000000" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="B1"
        android:textColor="#000000" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/button1"
        android:text="B2"
        android:textColor="#000000" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/button2"
        android:text="B3"
        android:textColor="#000000" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/button3"
        android:text="B4"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/button_indicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/textView4"
        android:layout_marginRight="33dp"
        android:text="No one"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button_indicator"
        android:layout_alignBottom="@+id/button_indicator"
        android:layout_marginRight="29dp"
        android:layout_toLeftOf="@+id/button_indicator"
        android:text="Entered: "
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

这篇关于获取按钮坐标和检测,如果手指是在他们 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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