[英]Some view elements won't hide, some won't appear
For some reason some of my view elements won't hide when I set Visibility to Gone
, others won't appear when I set it to Visible
. 出于某种原因,当我设置能见度我的一些观点的元素不会隐藏
Gone
,当我把它设置为别人不会出现Visible
。
In this example, cmdCallMe won't hide and cmdOk and cmdCancel won't appear. 在此示例中,cmdCallMe将不会隐藏,而cmdOk和cmdCancel将不会显示。 The other elements all behave as expected.
其他元素的行为均符合预期。
(source shortened slightly) (来源略有缩短)
Activity code: 活动代码:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.p2);
titleStatusView = FindViewById<TextView>(Resource.Id.lblP2Status);
outputTextView = FindViewById<TextView>(Resource.Id.lblP2Timer);
lblConfirm = FindViewById<TextView>(Resource.Id.lblP2Confirm);
cmdP2Update = FindViewById<Button>(Resource.Id.cmdP2Update);
cmdP2Arrived = FindViewById<Button>(Resource.Id.cmdP2Arrived);
cmdP2SelfDeployed = FindViewById<Button>(Resource.Id.cmdP2SelfDeployed);
cmdP2CallMe = FindViewById<Button>(Resource.Id.cmdP2CallMe);
cmdOk = FindViewById<Button>(Resource.Id.cmdP2CallMe);
cmdCancel = FindViewById<Button>(Resource.Id.cmdP2CallMe);
// hide normal buttons
// these all hide as expected
cmdP2Update.Visibility = ViewStates.Gone;
cmdP2Arrived.Visibility = ViewStates.Gone;
cmdP2SelfDeployed.Visibility = ViewStates.Gone;
// this should hide cmdCallMe but it doesn't change
cmdP2CallMe.Visibility = ViewStates.Gone;
// show confirm elements
// this appears as expected
lblConfirm.Visibility = ViewStates.Visible;
// the following 2 buttons should appear, but don't
cmdOk.Visibility = ViewStates.Visible;
cmdCancel.Visibility = ViewStates.Visible;
AXML: AXML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Status: EN-ROUTE"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lblP2Status"
android:gravity="center" />
<TextView
android:text="00:00:00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lblP2Timer"
android:gravity="center"
android:layout_marginBottom="19.0dp" />
<Button
android:text="Update"
android:layout_width="match_parent"
android:layout_height="64.5dp"
android:id="@+id/cmdP2Update"
android:layout_marginBottom="10.5dp"
android:background="@android:color/holo_green_dark" />
<Button
android:text="ARRIVED"
android:layout_width="match_parent"
android:layout_height="64.5dp"
android:id="@+id/cmdP2Arrived" />
<Button
android:text="SELF DEPLOYED"
android:layout_width="match_parent"
android:layout_height="64.5dp"
android:id="@+id/cmdP2SelfDeployed"
android:layout_marginBottom="10.5dp" />
<Button
android:text="CALL ME"
android:layout_width="match_parent"
android:layout_height="64.5dp"
android:id="@+id/cmdP2CallMe"
android:layout_marginTop="0.0dp" />
<TextView
android:text="Are you sure?"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lblP2Confirm"
android:gravity="center"
android:layout_marginBottom="16.0dp"
android:visibility="gone" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout1">
<Button
android:text="OK"
android:layout_width="190dp"
android:layout_height="wrap_content"
android:id="@+id/cmdOk"
android:visibility="gone" />
<Button
android:text="Cancel"
android:layout_width="190dp"
android:layout_height="wrap_content"
android:id="@+id/cmdCancel"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
When I step through all values are assigned as I would expect. 当我逐步浏览时,所有值均按预期分配。 I can't work out why the elements visibility doesn't always reflect this.
我无法弄清楚为什么元素可见性不能总是反映出来。
Look at your code : 看你的代码:
cmdP2CallMe = FindViewById<Button>(Resource.Id.cmdP2CallMe);
cmdOk = FindViewById<Button>(Resource.Id.cmdP2CallMe); <-- reference error here
cmdCancel = FindViewById<Button>(Resource.Id.cmdP2CallMe);<-- reference error here
:) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.