我有一个布局,有一个按钮,显示另一个视图,但只有一次,我的意思是,你点击按钮,它消失,并显示其他视图,第二次,你应该点击该按钮的父视图另一个视图(显示的那个视图)应该消失,并且按钮应该再次出现。我正在尝试clickable:false
和focusable:false
,但它不起作用。我怎样才能做到这一点?如何使父视图处理所有的OnClick事件?
相关代码
XML
<LinearLayout
android:id="@+id/item_tournament_header"
android:background="@drawable/bg_card_tournament"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="15">
<RelativeLayout
android:clickable="false"
android:focusable="false"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="match_parent">
<com.github.siyamed.shapeimageview.CircularImageView
android:id="@+id/item_friend_img_profile_pic"
android:layout_height="48dp"
android:layout_width="48dp"
android:layout_centerInParent="true"
android:scaleType="centerCrop"
android:src="@drawable/ic_profile"
app:siBorderColor="@color/white"/>
</RelativeLayout>
<LinearLayout
android:clickable="false"
android:focusable="false"
android:layout_weight="10"
android:layout_width="0dp"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:id="@+id/tournament_name"
android:textSize="@dimen/text_h3"
android:textStyle="bold"
android:textColor="@color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tournament_client"
android:textSize="@dimen/text_p"
android:textColor="@color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<RelativeLayout
android:clickable="false"
android:focusable="false"
android:layout_weight="2"
android:layout_width="0dp"
android:orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:id="@+id/btn_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/ic_plus_tournaments"/>
</RelativeLayout>
</LinearLayout>
的Java
btn_plus = (ImageView) findViewById(R.id.btn_plus);
TournamentContent =(LinearLayout)findViewById(R.id.item_tournament_content);
TournamentHeadaer =(LinearLayout)findViewById(R.id.item_tournament_header);
btn_plus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TournamentContent.setVisibility(View.VISIBLE);
btn_plus.setVisibility(View.GONE);
}
});
TournamentHeadaer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(btn_plus.getVisibility()==View.VISIBLE)
{
// It's not entering here!!!
TournamentContent.setVisibility(View.GONE);
btn_plus.setVisibility(View.VISIBLE);
}
}
});
是啊,我的思念试图责怪的工具之前仔细检查我的算法 – Aiapaec