【问题标题】:How to change side color of shapes in android如何在android中更改形状的侧面颜色
【发布时间】:2016-07-13 14:33:35
【问题描述】:

我是一名初学者。我想构建一个应用程序,但我遇到了一个问题。

如图所示,我有一个按钮。如果用户单击此按钮的顶部,我想仅更改顶行的颜色。在另一边,也就是用户点击的那一面。例如,如果用户单击顶部然后单击右侧,我想更改图片显示的两侧的颜色。

任何想法如何做到这一点?对我来说主要问题是我无法检测到用户点击了哪个区域。

【问题讨论】:

    标签: android image button line draw


    【解决方案1】:

    您可以使用如下所述的触摸检测: https://developer.android.com/training/gestures/detector.html

    @Override
    public boolean onSingleTapConfirmed(MotionEvent event) {
        float clickedX = event.getX();
        float clickedY = event.getY();
    
        float btnTop = obtainTop(yourBtn);
        float btnBot = obtainBot(yourBtn);
        float btnLeft = obtainLeft(yourBtn);
        float btnRight = obtainRight(yourBtn);
    
        // detect where the button was clicked
        // change button how you need
    
        return true;
    }
    

    要获得View 的 x y 坐标,你可以在这里找到一些东西 Getting View's coordinates relative to the root layout

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-03
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      • 2020-05-14
      • 1970-01-01
      相关资源
      最近更新 更多