如何同步的两种观点的绘制状态 [英] How to synchronize the drawable state of two views

查看:141
本文介绍了如何同步的两种观点的绘制状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android的我有一个EditText和旁边的EditText一个按钮,每当我在一个preSS我想其他出现在相同的状态也是如此。

In Android I have an EditText and a Button next to the EditText, and whenever I press on one I would like the other to appear in the same state as well.

我试图把机器人:我的EditText和按钮,但是这仅适用duplicateParentState =真如果我触摸布局本身:点击=真的封闭布局和android。如果我摸摸我的EditText或按钮没有任何反应。我尝试设置的android:点击上的EditText&安培=假;按钮,但触摸事件仍然没有渗透到父。

I tried putting android:clickable = "true" on the enclosing layout and android:duplicateParentState="true" on my EditText and Button but this only works if I touch the layout itself. If I touch my EditText or Button nothing happens. I tried setting android:clickable = "false" on the EditText & Button but the touch events still don't filter down to the parent.

我怎样才能让我的看法透明,使他们向下传递给父触摸事件?我要的是对的EditText和Button一起工作,所以如果我触摸任何一个他们都显得pressed。

How can I make my views transparent to touch events so they pass down to the parent? What I want is for the EditText and Button to work together so if I touch either one they both appear to be pressed.

下面是我目前使用XML:

Here is the XML I am currently using:

<RelativeLayout
    android:id = "@+id/EnclosingLayout"
    android:layout_width = "fill_parent"
    android:layout_height = "120dp"
    android:clickable = "true">
    <EditText
        android:id = "@+id/MyEditText"                                                      
        android:layout_width = "fill_parent"
        android:layout_height = "wrap_content"
        android:layout_weight = "1"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:clickable="false"
        android:duplicateParentState="true"/>
    <Button
        android:id = "@+id/MyButton"
        android:layout_alignTop="@id/MyEditText"
        android:layout_alignBottom="@id/MyEditText"
        android:layout_alignParentRight="true"
        android:duplicateParentState="true"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_width="31.33dp"
        android:gravity="center"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:clickable="false"/>
</RelativeLayout>


推荐答案

请考虑捕获所有输入到编辑文本和按钮和事件重定向到公共视图控制器,在这种情况下,一个常用的方法。然后更新无论是在常用的方法编辑文本和按钮(视图控制器)。对于编辑文本,您将需要两个陷阱触摸和点击通过创建这两个事件的处理程序为:

Consider trapping all input to the edit text and button and redirecting the event to a common view controller, in this case, a common method. Then update both the edit text and button in the common method (a view controller). For the edit text you will need to trap both on touch and on click by creating a handler for both events as in:

// EDIT TEXT ON TOUCH HANDLER
editTextPassword.setOnTouchListener(new View.OnTouchListener() {    
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub  
            switch (event.getAction()){
                case MotionEvent.ACTION_DOWN:
                    SynchViews();  // view controller
                    break;
            }           
            return true;
        }
    });

// EDIT TEXT ON Click HANDLER (No touch screen)
editTextPassword.setOnClickListener(new OnClickListener() { 
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub  
                        SynchViews();   // view controller
        }
    });

这篇关于如何同步的两种观点的绘制状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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