Android:为什么只能在屏幕顶部听到点击而不是分配的视图?

时间:2012-12-26 04:36:26

标签: android relativelayout tablelayout onclicklistener

我的应用使用以编程方式生成的TableLayouts显示在RelativeLayout上方。 TableLayout中的第一行包括一个分配了onClickListener的TextView。 TableLayouts使用TranslateAnimation显示在屏幕的BOTTOM上。令人费解的是,正在听到咔嗒声,但只是在ActionBar正下方的屏幕顶部。另外只有一个听众正在开火。我必须承认我对此感到困惑。我以为使用android:descendantFocusability="blocksDescendants">会解决它,但没有这样的运气。在将设计转换为ListView之前(我不想这样做)我希望StackOverflow专家可以帮助解决这个问题。

以下是显示2个生成的TableLayouts的屏幕截图: screenshot

这是RelativeLayout父级:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/GPSTrackerRelativeLayout_root"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:descendantFocusability="blocksDescendants">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:layout_alignParentTop="true"
    android:layout_centerInParent="true"
    android:orientation="horizontal"
    android:id="@+id/ButtonAndSpinnerRow"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:visibility="visible"
    android:background="@drawable/tab_unselected_pressed_eagleeyeactionbar" >

        <Button
            android:id="@+id/Time_period_select_button"
            android:clickable="true" 
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android1:layout_gravity="fill_vertical|center_horizontal"
            android:gravity="center"
            android:text="@string/selectTimeAndDate"
            android:textColor="@color/white"
            android:textSize="14sp"
            android:textStyle="bold"
            android1:background="@drawable/petes_custom_click_action_button" />

        <Spinner
            android:id="@+id/GPS_unit_select_spinner"
            android:clickable="true" 
            android:layout_width="0dp"
            android:layout_height="45dp"
            android:layout_weight="3"
            android:gravity="center"
            android:textSize="20sp"
            android:textStyle="bold" />
</LinearLayout>

<View
    android:id="@+id/firstDivider"
    style="@style/horizontal_line" />

<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    style="@style/mapView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/ButtonAndSpinnerRow"
    android:apiKey="MYKEY"
    android:clickable="true" >
 </com.google.android.maps.MapView>
 </RelativeLayout>

这是生成可点击按钮的代码。 Button位于该行的第二列。图像位于第一列

    // Add NAME to 1st row 
      watchAreaName[overlayNumber] = new Button(this); // findViewById(R.id.WatchArea_Name);
      watchAreaName[overlayNumber].setText("\"" + ControlPanel.pWatchAreaName[GPS_unit_selected][iWatch] + "\" Watch Activity");
      watchAreaName[overlayNumber].setPadding(1, 1, 1, 1); // left, top, right, bottom
      watchAreaName[overlayNumber].setTextSize(HEADER_ROW1_TEXT_SIZE);
      watchAreaName[overlayNumber].setTextColor(Color.WHITE); // deep blue=parseColor("#00297C")
      watchAreaName[overlayNumber].setTypeface(null, Typeface.BOLD);
      watchAreaName[overlayNumber].setGravity(Gravity.CENTER); // (Gravity.CENTER_VERTICAL | Gravity.LEFT)
      watchAreaName[overlayNumber].setFocusable(false); 
      watchAreaName[overlayNumber].setId(GPSTrackerOverlayLayout_ids[overlayNumber]);  //set ID equivalent to parent
      watchAreaName[overlayNumber].setTag(iWatch+ "=|"+ControlPanel.pWatchAreaName[GPS_unit_selected][iWatch]+ "|");

// Add to parent TableRow, then set LayoutParams headerRow[overlayNumber].addView(watchAreaName[overlayNumber]); TableRow.LayoutParams watchAreaName_layout_params = (TableRow.LayoutParams) watchAreaName[overlayNumber].getLayoutParams(); watchAreaName_layout_params.column = SECOND_COLUMN; // place in 2nd column watchAreaName_layout_params.height = HEADER_ROW1_HEIGHT; // TableRow.LayoutParams.WRAP_CONTENT; watchAreaName_layout_params.width = 0; //COLUMN_LABELS_WIDTH; watchAreaName_layout_params.weight = (float) .85; watchAreaName_layout_params.span = 1; // span this many columns (optional) watchAreaName[overlayNumber].setLayoutParams(watchAreaName_layout_params); // watchAreaName[overlayNumber].setBackgroundColor(watchAreaColorIds[watchAreaBackgroundColorSelections[overlayNumber]]); watchAreaName[overlayNumber].setClickable(true); watchAreaName[overlayNumber].setOnClickListener(new ShowHideOverlayListener()); // add finished Header row to TableLayout parent GPSTrackerOverlayLayout[overlayNumber].addView(headerRow[overlayNumber], new TableLayout.LayoutParams(TABLE_MATCH_PARENT, TABLE_WRAP_CONTENT)); // width, height headerRow[overlayNumber].setFocusable(false);

0 个答案:

没有答案