Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RelativeLayout refresh after view.setVisibility(View.GONE) and view.setVisibility(View.VISIBLE)

Please look at the following image to understand the problem:

enter image description here

As you can see, there is a RelativeLayout which holds a custom View and a LinearLayout.
Between them, there is also another View, which Visibility is set to GONE. Now, when I press the Button, I would like to change the visibility of that GONE View to VISIBLE, and rearrange the RelativeLayout, so that the third View gets between custom View and LinearLayout. When I press another button, I would like to make third view GONE again. How can I achieve that?

Here is my XML:

<view
    android:id="@+id/CanvasView"
    android:layout_width="200dp"
    android:layout_height="40dp"
    android:layout_above="@+id/HorizontalScrollView"
    android:layout_centerHorizontal="true"
    android:layout_margin="0dp"
    android:layout_marginBottom="0dp"
    android:layout_marginTop="0dp"
    class="com.example.CanvasView"
    android:orientation="vertical" />

<HorizontalScrollView
    android:id="@+id/HorizontalScrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/linearLayout2"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:visibility="gone" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:orientation="horizontal" >

    //SOME BUTTONS HERE
    </LinearLayout>

</HorizontalScrollView>

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="5dp" >

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:layout_weight="0.4"
        android:maxWidth="200dp"
        android:text="Clear"
        android:textColor="@android:color/white"
        android:textSize="20sp" />

    <Button
        android:id="@+id/settingsButton"
        android:layout_width="44dp"
        android:layout_height="44dp"
        android:layout_gravity="center_vertical|center_horizontal"
        android:background="@drawable/settings_button_selector" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:layout_weight="0.4"
        android:enabled="false"
        android:maxWidth="200dp"
        android:text="Recognize"
        android:textColor="@android:color/white"
        android:textSize="20sp" />

</LinearLayout>

If I only setVisibility of the third view in OnClick() method, it will appear above LinearLayout and it will overlay the custom View (I tried it before). In other words, it will not move RelativeLayout up.

like image 298
Marek Avatar asked Jul 01 '13 07:07

Marek


People also ask

What is android View View?

View is a basic building block of UI (User Interface) in android. A view is a small rectangular box that responds to user inputs. Eg: EditText, Button, CheckBox, etc. ViewGroup is an invisible container of other views (child views) and other ViewGroup.

What is View tag in android?

Tags are essentially an extra piece of information that can be associated with a view. They are most often used as a convenience to store data related to views in the views themselves rather than by putting them in a separate structure. Reference: http://developer.android.com/reference/android/view/View.html.

How do I create a View Center in RelativeLayout?

Below that, the layout_height=0 and layout_weight=1 attributes on the RelativeLayout cause it to take up all the remaining space. You can then center the button in the RelativeLayout . You can play with padding on the button to get it to the size you want.


1 Answers

findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
     public void onClick(View v) {
         findViewById(R.id.hiddenview).setVisibility(View.GONE);
         findViewById(R.id.relativelayout).invalidate();
     }
});
findViewById(R.id.button2).setOnClickListener(new OnClickListener(){
     public void onClick(View v) {
         findViewById(R.id.hiddenview).setVisibility(View.VISIBLE);
         findViewById(R.id.relativelayout).invalidate();
     }
});
like image 183
Alex Gittemeier Avatar answered Sep 17 '22 04:09

Alex Gittemeier