我需要创建一个像下面这样的片段。
点击Need Cash TextView
将更改包含的布局,其中包含两个按钮Cancel
& Meet
并在这些观点之间切换。
但是当我点击需要现金通话时,toggleVisibility()
功能会使Need Cash
隐身,但不显示Cancel | Meet
。
我在这个过程中犯了什么错误?
|----------------------| => |----------------------|
| | => | |
| | => | |
| | => | |
| | => | |
| | => | |
| | => | |
| | => | |
| | => | |
| | => | |
| | => | |
|----------------------| => |----------------------|
| Need Cash | => | Cancel | Meet |
|----------------------| => |----------------------|
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.tv_need_cash:
toggleVisibility();
break;
case R.id.tv_need_cash_cancel:
toggleVisibility();
Toast.makeText(getActivity(), "tv_need_cash_cancel", Toast.LENGTH_SHORT).show();
break;
case R.id.tv_need_cash_lets_meet:
toggleVisibility();
Toast.makeText(getActivity(), "tv_need_cash_lets_meet", Toast.LENGTH_SHORT).show();
break;
}
}
public void toggleVisibility() {
if(needCashTv.getVisibility() == View.VISIBLE) {
//needCashTv.setEnabled(false);
needCashTv.setVisibility(View.GONE);
frameForNeedCashStuff.bringToFront();
frameForNeedCashStuff.setVisibility(View.VISIBLE);
//cancelNeedCashTv.setEnabled(true);
cancelNeedCashTv.setVisibility(View.VISIBLE);
//letsMeetneedCashTv.setEnabled(true);
letsMeetneedCashTv.setVisibility(View.VISIBLE);
}
else {
//needCashTv.setEnabled(true);
needCashTv.setVisibility(View.VISIBLE);
needCashTv.bringToFront();
frameForNeedCashStuff.setVisibility(View.GONE);
//cancelNeedCashTv.setEnabled(false);
cancelNeedCashTv.setVisibility(View.GONE);
//letsMeetneedCashTv.setEnabled(false);
letsMeetneedCashTv.setVisibility(View.GONE);
}
thisView.invalidate();
}
.....................OTHER WIDGETS ABOVE......................
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:id="@+id/frameForNeedCashStuff">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:visibility="gone">
<TextView
android:layout_width="200dp"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:layout_alignParentLeft="true"
android:background="@color/ColorPrimary"
android:gravity="center"
android:id="@+id/tv_need_cash_cancel"
android:text="@string/button_cancel"
android:textSize="@dimen/text_sizes_small"
android:textColor="@color/White"
android:visibility="gone"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:layout_alignParentRight="true"
android:background="@color/ColorPrimary"
android:gravity="center"
android:id="@+id/tv_need_cash_lets_meet"
android:text="Let's Meet"
android:textSize="@dimen/text_sizes_small"
android:textColor="@color/White"
android:visibility="gone"/>
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:background="@color/ColorPrimary"
android:layout_alignParentBottom="true"
android:gravity="center"
android:id="@+id/tv_need_cash"
android:text="@string/need_cash"
android:textSize="@dimen/text_sizes_small"
android:textColor="@color/White"
android:visibility="visible" />
</RelativeLayout>
.....................OTHER WIDGETS BELOW......................
修改
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View thisView = inflater.inflate(R.layout.fragment_map, container, false);
return thisView;
}
编辑2
点击之前的片段视图,显示保持现金TextView
点击后的片段视图未显示&#39;取消&#39;并且&#39;见面&#39; TextViews
**编辑3 ** 给予外部RelativeLayout的id并使其无效
public void toggleVisibility() {
if(needCashTv.getVisibility() == View.VISIBLE) {
//needCashTv.setEnabled(false);
needCashTv.setVisibility(View.GONE);
frameForNeedCashStuff.setVisibility(View.VISIBLE);
//cancelNeedCashTv.setEnabled(true);
cancelNeedCashTv.setVisibility(View.VISIBLE);
//letsMeetneedCashTv.setEnabled(true);
letsMeetneedCashTv.setVisibility(View.VISIBLE);
frameForNeedCashStuff.bringToFront();
}
else {
//needCashTv.setEnabled(true);
needCashTv.setVisibility(View.VISIBLE);
needCashTv.bringToFront();
frameForNeedCashStuff.setVisibility(View.GONE);
//cancelNeedCashTv.setEnabled(false);
cancelNeedCashTv.setVisibility(View.GONE);
//letsMeetneedCashTv.setEnabled(false);
letsMeetneedCashTv.setVisibility(View.GONE);
}
((ViewGroup)frameForNeedCashStuff2.getParent()).invalidate();
//thisView.invalidate();
}
修复后的工作代码 编辑4
public void toggleVisibility() {
if(needCashTv.getVisibility() == View.VISIBLE) {
needCashTv.setVisibility(View.GONE);
frameForNeedCashStuff2.setVisibility(View.VISIBLE);
}
else {
needCashTv.setVisibility(View.VISIBLE);
needCashTv.bringToFront();
frameForNeedCashStuff2.setVisibility(View.GONE);
}
((ViewGroup)frameForNeedCashStuff.getParent()).invalidate();
}
<FrameLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:id="@+id/frameForNeedCashStuff">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:visibility="gone"
android:id="@+id/frameForNeedCashStuff2">
<TextView
android:layout_width="200dp"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:layout_alignParentLeft="true"
android:background="@color/ColorPrimary"
android:gravity="center"
android:id="@+id/tv_need_cash_cancel"
android:text="@string/button_cancel"
android:textSize="@dimen/text_sizes_small"
android:textColor="@color/White"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:layout_alignParentRight="true"
android:background="@color/ColorPrimary"
android:gravity="center"
android:id="@+id/tv_need_cash_lets_meet"
android:text="Let's Meet"
android:textSize="@dimen/text_sizes_small"
android:textColor="@color/White"/>
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:background="@color/ColorPrimary"
android:layout_alignParentBottom="true"
android:gravity="center"
android:id="@+id/tv_need_cash"
android:text="@string/need_cash"
android:textSize="@dimen/text_sizes_small"
android:textColor="@color/White"
android:visibility="visible" />
</FrameLayout>
答案 0 :(得分:0)
RelativeLayout
TextView
包裹tv_need_cash_cancel
tv_need_cash_lets_meet
和View.invalidate()
已设置为“已消失”。
如果您只是切换子视图的可见性,它将永远不会显示。
您确定还需要regexp {.*%MKA-5-SESSION_START: +\((.*) +:.*\) +MKA Session started for.*([0-9A-Fa-f]{4}.[0-9A-Fa-f]{4}.[0-9A-Fa-f]{4}).*AuditSessionID +(.*), +AuthMgr-Handle +(.*)} $op - intf mac auditsessid authmgrhdl
吗?如果您只是切换可见性,则没有必要。