使布局隐形Android

时间:2015-11-03 09:13:45

标签: c# android xamarin

我有线性布局。

我希望它在文本添加到文本字段之前不可见。

代码

private void Display (){
        LinearLayout display2 = FindViewById<LinearLayout> (Resource.Id.linearLayout12);        
        //LinearLayout display = FindViewById<LinearLayout> (Resource.Id.linearLayout13);           
        TextView productname = FindViewById<TextView> (Resource.Id.posttittle);
        TextView price = FindViewById<TextView> (Resource.Id.price);
        TextView weight = FindViewById<TextView> (Resource.Id.weight);

        productname.Text = Intent.GetStringExtra("title");

        price.Text = Intent.GetStringExtra("price");
        weight.Text = Intent.GetStringExtra("weight");
        display2.Visibility = ViewStates.Visible;
        productname.Visibility = ViewStates.Visible;
        price.Visibility = ViewStates.Visible;
        weight.Visibility = ViewStates.Visible;
    }

我的斧头

&#13;
&#13;
 <ScrollView
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="390.3dp"
        android:id="@+id/scrollView2"
        android:background="@drawable/middle1">
        <LinearLayout
            android:orientation="vertical"
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/linearLayout12"
            android:visibility = "gone">
            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="147.6dp"
                android:id="@+id/linearLayout13">
                <LinearLayout
                    android:orientation="vertical"
                    android:minWidth="25px"
                    android:minHeight="25px"
                    android:layout_width="184.9dp"
                    android:layout_height="match_parent"
                    android:id="@+id/linearLayout15">
                    <TextView
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:layout_width="181.9dp"
                        android:layout_height="63.3dp"
                        android:id="@+id/posttittle"
                        android:textColor="#ffffffff"
                        android:layout_marginLeft="7.7dp"
                        android:textSize="14sp"
                        android:visibility="gone" />
                    <LinearLayout
                        android:orientation="horizontal"
                        android:minWidth="25px"
                        android:minHeight="25px"
                        android:layout_width="match_parent"
                        android:layout_height="93.8dp"
                        android:id="@+id/linearLayout16">
                        <TextView
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:layout_width="wrap_content"
                            android:layout_height="48.7dp"
                            android:id="@+id/price"
                            android:layout_marginTop="39.8dp"
                            android:layout_marginLeft="5.5dp"
                            android:textColor="#ffffffff"
                            android:visibility="gone" />
                        <TextView
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:layout_width="58.8dp"
                            android:layout_height="53.3dp"
                            android:id="@+id/weight"
                            android:layout_marginLeft="21.5dp"
                            android:layout_marginTop="41.9dp"
                            android:textColor="#faaf56"
                            android:paddingTop="7dp"
                            android:visibility="gone" />
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
             <LinearLayout
                android:orientation="horizontal"
                android:minWidth="25px"
                android:minHeight="25px"
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:id="@+id/linearLayout23"
                android:background="#99999999" />
        </LinearLayout>
    </ScrollView>
&#13;
&#13;
&#13;

但是当我启动活动时,我会看到线性布局。

也许是因为我在OnCreate中调用了Display()?

我怎样才能做到线性布局?#34;走了&#34;直到Display()运行?

2 个答案:

答案 0 :(得分:0)

display2.setVisibility(View.INVISIBLE);
display2.setVisibility(View.GONE);

会使你的linearlayout不可见。

    display2.setVisibility(View.VISIBLE);

会让它出现。

答案 1 :(得分:0)

这就是答案

    private void Display (){
        LinearLayout display2 = FindViewById<LinearLayout> (Resource.Id.linearLayout12);        
        //LinearLayout display = FindViewById<LinearLayout> (Resource.Id.linearLayout13);           
        TextView productname = FindViewById<TextView> (Resource.Id.posttittle);
        TextView price = FindViewById<TextView> (Resource.Id.price);
        TextView weight = FindViewById<TextView> (Resource.Id.weight);


        productname.Text = Intent.GetStringExtra ("title");

        if (productname.Text == Intent.GetStringExtra ("title")) {
            display2.Visibility = ViewStates.Visible;
        } 
        else {
            display2.Visibility = ViewStates.Gone;
        }


        price.Text = Intent.GetStringExtra("price");
        weight.Text = Intent.GetStringExtra("weight");
        //display2.Visibility = ViewStates.Visible;
        productname.Visibility = ViewStates.Visible;
        price.Visibility = ViewStates.Visible;
        weight.Visibility = ViewStates.Visible;
    }