0 votes
in Programming by (2k points)

So my layout is still visible, maybe someone sees mistake? I want to dispear it when infoButton(imagebutton) is clicked.

FrameLayout infolayout;
infolayout = (FrameLayout) findViewById(R.id.infoLayout);
public void infoPressed(View v){//info button is pressed by user
        //infoLayout.setVisibility(View.GONE); 

        infolayout.setVisibility(View.INVISIBLE);
    }

    <FrameLayout
    android:layout_width="193dp"
    android:layout_height="200dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignBottom="@+id/serviceLayout"
    android:id="@+id/infoLayout">

I wacthed: How to change visibility of layout programaticly

EDITED: wrong code part, still not working for me!

1 Answer

0 votes
by (1.9k points)
*Try this**
    <RelativeLayout 
    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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.demo.MainActivity" >

<FrameLayout
    android:id="@+id/serviceLayout"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:background="#000000" />

<Button
    android:id="@+id/btnHide"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:onClick="infoPressed"
    android:text="Hide" />

</RelativeLayout>


**MainActivity.java**
public class MainActivity extends Activity
{
  FrameLayout infolayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    infolayout = (FrameLayout) findViewById(R.id.serviceLayout);
}
public void infoPressed(View v){//info button is pressed by user
    //infoLayout.setVisibility(View.GONE); 

    infolayout.setVisibility(View.INVISIBLE);
}

}

...