我有一個佈局,有一個按鈕,顯示另一個視圖,但只有一次,我的意思是,你點擊按鈕,它消失,並顯示其他視圖,第二次,你應該點擊該按鈕的父視圖另一個視圖(顯示的那個視圖)應該消失,並且按鈕應該再次出現。我正在嘗試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