java - 如何在 android studio 中将 GONE 可见性更改为 VISIBLE 可见性

标签 java android xml

在我的应用程序中,我将 Frame Layout 可见性设置为 GONE,并且我想在单击复选框时显示 Frame 布局。是否可以将其设置为 VISIBLE?

xml:这是整个xml代码

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/Container">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/red_logo"/>

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Marchant Offer"
    android:textSize="30px"
    android:textColor="#ff0000"/>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <Spinner
        android:id="@+id/spinnerCountry"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </Spinner>

    <TextView
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Country" />

</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <Spinner
        android:id="@+id/spinnerState"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </Spinner>

    <TextView
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="State/Province" />

</LinearLayout>

<EditText
    android:id="@+id/editTextCity"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="City"/>

<EditText
    android:id="@+id/editTextAirport"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Neareast Airport"/>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <Spinner
        android:id="@+id/spinnerCategory"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </Spinner>

    <TextView
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Category" />


</LinearLayout>

<EditText
    android:id="@+id/editSTextOfferTitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Offer Title"/>

<EditText
    android:id="@+id/editTextOfferSummary"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Offer Summary"/>


<EditText
    android:id="@+id/editTextOfferDescription"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Offer Description"/>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Offer Highlights"/>

    <Button
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Add"/>
</LinearLayout>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Inclusion"/>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Others Inclusion"/>

    <Button
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Add"/>
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Do You Offer Inclusive Hotel/Port Pick-Up and Drop-off"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <CheckBox
        android:id="@+id/checkBoxYes"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

        <TextView
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Yes"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <CheckBox
            android:id="@+id/checkBoxNo"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />


        <TextView
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="No"/>
    </LinearLayout>
</LinearLayout>

 <FrameLayout
    android:id="@+id/frameLayout"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:visibility="gone">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/ifyes"/>

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Your picking up coverage area"/>

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="Time to picking up the Guess"/>

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="Additional Info for Guess"/>
    </LinearLayout>
  </FrameLayout>
 </LinearLayout>
</ScrollView>

java代码:

checkBoxYes = (CheckBox)findViewById(R.id.checkBoxYes);
checkBoxYes.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if(isChecked){
            frameLayout.setVisibility(View.VISIBLE);
        }
    }
});

最佳答案

是的..

ch = (CheckBox)findViewById(R.id.checkbox);              
ch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

    @Override
    public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
        if(isChecked){
            framelayout.setVisibility(View.VISIBLE);//framelayout is your layout,initially set GONE.
        }
    }
  }); 

关于java - 如何在 android studio 中将 GONE 可见性更改为 VISIBLE 可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35907961/

相关文章:

java - 电子邮件应用程序无法在真实设备上运行

java - 无法通过 setActionBar 设置工具栏(Android)

android - 蓝色全息颜色在设备上显示为绿色

xml - 在 styles.xml 中设置特定字体

android - 在另一个布局中以编程方式膨胀布局

java - 如何在Java中移动签名XML中的签名节点

java - LibGDX gwd 不继承所需的模块

java - 在 tomcat/shared/lib 中获取 jar 以使用调用它们的 webapp 的配置进行记录

java - Hibernate:实现POP方法

android - 在 xml 中设置复选框的可绘制对象