点击父母影响孩子也

时间:2016-09-30 22:29:02

标签: android android-layout

以下是我的代码

$ irb
2.3.1 :001 > require 'date'
 => true 
2.3.1 :002 > Date.parse '30/08/2016'
 => #<Date: 2016-08-30 ((2457631j,0s,0n),+0s,2299161j)> 
2.3.1 :003 > Date.parse '30 08 2016'
 => #<Date: 2016-09-30 ((2457662j,0s,0n),+0s,2299161j)> 
2.3.1 :004 > 

但是当我点击LinearLayout时,会调用函数hello。 我想在单击LinearLayout时不应该调用函数hello 任何建议?

2 个答案:

答案 0 :(得分:0)

我不确定会有多准确。

        @Override
            public boolean onTouchEvent(MotionEvent event) { 

        Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics mertrics = new DisplayMetrics ();
    display.getMetrics(metrics);

    float density  = getResources().getDisplayMetrics().density;
    float dpHeight = metrics.heightPixels / density;
                float y = (float)event.getY();  
                switch (event.getAction()) {
                    case MotionEvent.ACTION_MOVE:
                         if(y < dpHeight / 2 + 50 && y > dpHeight / 2 - 50){
    //no hello() here
    }
else
{
            // call hello() here and remove it from layout
        }
                }
            return false;
            }

答案 1 :(得分:0)

您将android:onclick="hello"放在错误的位置。试试这段代码,让我知道结果

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/dialog"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:onclick="hello"
    android:layout_centerVertical="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:orientation="vertical"
        android:background="#FFFFEE"
        android:layout_centerVertical="true"
        android:clickable="false"
        android:id="@+id/ll">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"        
            android:id="@+id/title"/>
     </LinearLayout>
 <RelativeLayout>
祝你好运:)