我在可折叠工具栏中有一个自定义视图 - 一个相对布局,其中EditText
和TextView
充当按钮。展开可折叠工具栏时,这些小部件对点击的响应都很好。
但是,当我折叠工具栏时,两个小部件都是可见的并且可以点击(记录isClickable()
来计算出来),但TextView
按钮没有响应点击。但是EditText
效果很好。
崩溃后为什么TextView
没有响应(即使可点击)?
编辑:添加了代码。
折叠工具栏布局的XML。
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/custom_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/PrimaryDark"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleEnabled="true">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:clipChildren="false"
android:clipToPadding="false"
android:minHeight="?attr/actionBarSize"
android:paddingBottom="@dimen/SpaceSmall"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1.0">
<TextView
android:id="@+id/header_title"
android:layout_width="match_parent"
android:layout_height="@dimen/HeightMax"
android:layout_marginLeft="@dimen/SpaceSmall"
android:layout_marginRight="@dimen/Space"
android:layout_toRightOf="@id/iv_custom_header_up_arrow"
android:ellipsize="end"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="@color/p2pWhiteTextPrimary"
android:textSize="@dimen/p2pTextTitle"/>
<LinearLayout
android:id="@+id/ll_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/MarginTop"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:paddingRight="@dimen/Space">
<RelativeLayout
android:layout_width="match_parent"
android:id="@+id/plans"
android:layout_height="@dimen/EmptyHeight"
android:clipChildren="false"
android:gravity="center_vertical">
<TextView
android:id="@+id/symbol"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginLeft="@dimen/p2p_transaction_rupee_left_margin"
android:text="@string/symbol"
android:textColor="@color/TextPrimary"
android:textSize="@dimen/TextHeading"/>
<EditText
android:id="@+id/et_box"
style="@style/EditTextBoxHoloDark"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/Space"
android:hint="@string/empty_box"
android:textColorHint="@color/colorTextHintText"
android:inputType="numberPassword"
android:maxLength="7"
android:singleLine="true"
android:textSize="@dimen/EmptyET"
android:cursorVisible="true"
android:layout_toRightOf="@+id/ymbol"
android:layout_toLeftOf="@+id/plans">
<requestFocus />
</EditText>
<TextView
android:id="@+id/plans"
style="@style/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:clickable="true"
android:paddingLeft="@dimen/Small"
android:paddingRight="@dimen/Small"
android:paddingTop="@dimen/Tiny"
android:paddingBottom="@dimen/Tiny"
android:text="@string/plans"
android:textAllCaps="false"
android:textSize="@dimen/caption"
android:visibility="invisible"
android:layout_centerVertical="true"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
onOffsetChangedListener()
预先计算初始和增量位置值,以便在偏移更改时使窗口小部件转换
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
float percentageDone = Math.abs(verticalOffset) * 100 / appBarLayout.getTotalScrollRange();
et.setScaleX(1 - (1 - deltaTextSize) * percentageDone / 100.0f);
et.setScaleY(1 - (1 - deltaTextSize) * percentageDone / 100.0f);
et.setX(initialXAmount - (deltaXAmount) * percentageDone / 100.0f);
et.setY(initialYAmount - (deltaYAmount) * percentageDone / 100.0f);
viewPlans.setY(initialPlanPosition - (deltaPlanPosition) * percentageDone / 100.0f);
}
});
}
});