我有一个布局,有一个显示另一个 View 的按钮,但只显示一次,我的意思是,您单击该按钮,它消失并显示另一个 View ,第二次您应该单击该 View 的父 View 按钮和另一个 View (显示的 View )应该消失,并且按钮应该再次出现。我正在尝试使用 clickable:false
和 focusable:false
但它不起作用。我怎样才能实现这一目标?
相关代码
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);
}
}
});
最佳答案
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.GONE)
{
// It's not entering here!!!
TournamentContent.setVisibility(View.GONE);
btn_plus.setVisibility(View.VISIBLE);
}
}
});
关于android - 如何让父 View 处理所有的OnClick事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33480864/