1

我的应用程序使用显示在RelativeLayout 上方的以编程方式生成的TableLayout。TableLayout 中的第一行包括一个分配了 onClickListener 的 TextView。TableLayouts 使用 TranslateAnimation 显示在屏幕的底部。莫名其妙地,听到了点击,但只在屏幕顶部的操作栏下方。再加上只有一名听众在开火。我必须承认我对此感到困惑。我认为使用android:descendantFocusability="blocksDescendants">可以解决它,但没有这样的运气。在将设计转换为 ListView(我不想这样做)之前,我希望 StackOverflow 专家可以帮助解决这个问题。

这是显示生成的 2 个 TableLayouts 的屏幕截图: 截屏

这是 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>

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

    // 将 NAME 添加到第一行
      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); // 左上右下
      watchAreaName[overlayNumber].setTextSize(HEADER_ROW1_TEXT_SIZE);
      watchAreaName[overlayNumber].setTextColor(Color.WHITE); // 深蓝色=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]); //设置ID等同于父级
      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);

4

0 回答 0