2016-03-10 2 views
0

В моем приложении я установил видимость рамки для GONE, и я хочу показать макет фрейма, когда я нажму на флажок. возможно ли установить его ВИДИМО?Как изменить видимость GONE для видимой видимости в студии android

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); 
     } 
    } 
}); 
+0

'FrameLayout' height is' wrap_content' изменить его на 'match_parent' – Bharatesh

ответ

0

да ..

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. 
     } 
    } 
    }); 
+0

благодарим за ответ, но у меня есть тот же код с кодом выше, и он не работал должным образом. –

0

попробовать этот способ, которым это поможет вам

private int checkedBoxs = 0; 
private final CheckBox.OnCheckedChangeListener listener = 
    new OnCheckedChangeListener() { 
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
      if (isChecked) { 
       status.set(position, true); 
       checkedBoxs++; 
       if (layout.getVisibility() == View.GONE) 
        layout.setVisibility(View.VISIBLE); 
      } else { 
       status.set(position, false); 
       checkedBoxs--; 
       if (checkedBoxs == 0) 
        layout.setVisibility(View.GONE); 
      } 
     } 
    }; 
+0

извините, но я немного смущаюсь с этим кодом, когда я должен объявлять статус и позицию? извините, но это мой первый раз, поэтому, пожалуйста, проводите меня. спасибо –

+0

Что вы имеете в виду с положением и статусом? –

+0

status.set (position, true). нам нужно сначала объявить это? –

0

Возможно, это связано с тем, что видимость просмотров внутри рамки вашего макета также отсутствует.

Попробуйте код, приведенный ниже

checkBoxYes = (CheckBox)findViewById(R.id.checkBoxYes); 
    ViewGroup frameLayout = (ViewGroup)findViewById(R.id.frameLayout) 
    checkBoxYes.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
@Override 
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
    if(isChecked){ 
     frameLayout.setVisibility(View.VISIBLE); 
     int count = frameLayout.getChildCount(); 
    for (int i = 0; i < count; i++) { 
     View view = frameLayout.getChildAt(i); 
     view.setVisibility(View.VISIBLE); 
    } 
    } 
} 

});

Убедитесь, что ваш frameLayout включен в ViewGroup.

+0

мой макет кадра не пуст. он содержит линейную компоновку и три редактирования текста. –

+0

Изменили мой ответ. попробуйте. –

+0

Где вы объявили mViewGroup? –