Android: the background image does not appear the first time it comes from invisible to visible

I have a relativelayout inside a relativelayout, and all this inside an include. External relativelayout has android: background, which is an image.
The inside has a different image, but the same. All this is invisible. There is a button that is responsible for changing visibility.

When it becomes visible, the internal image is displayed, but the external image is not.
BUT, if I click to hide, and then click again to show - the external image is also displayed.

Here is the corresponding xml:

<RelativeLayout
    android:id="@+id/display_prefs_dialog_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:visibility="invisible" >

    <include
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="45dp"
        android:layout_marginRight="50dp"
        layout="@layout/display_prefs_dialog" >
    </include>
</RelativeLayout>

And inside include include:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/display_prefs_dialog"
    android:layout_width="327dp"
    android:layout_height="218dp"
    android:background="@drawable/display_win" >

    <RelativeLayout
        android:id="@+id/display_letters_bg"
        android:layout_width="262dp"
        android:layout_height="44dp"
        android:layout_marginLeft="32dp"
        android:layout_marginTop="38dp"
        android:background="@drawable/display_letter_frame" >

JAVA Code:

final ImageButton btnDisplay = (ImageButton) findViewById(R.id.btnDisplay);         
        final RelativeLayout prefsInnerDialog = (RelativeLayout) findViewById(R.id.display_prefs_dialog);       
        final RelativeLayout prefsDialog = (RelativeLayout) findViewById(R.id.display_prefs_dialog_layout);


btnDisplay.setOnClickListener(new Button.OnClickListener() 
        {
            public void onClick(View v)
            {                               
                int visibility = prefsDialog.getVisibility();
                if (visibility == View.VISIBLE) 
                {
                    prefsDialog.setVisibility(View.INVISIBLE);
                } 
                else 
                {
                    prefsDialog.setVisibility(View.VISIBLE);
                }
            }
        });
+3
source share
1 answer

, , - , . , ..!

Java: Main.java

public class Main extends Activity {
    RelativeLayout prefsInnerDialog, prefsDialog;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        prefsInnerDialog = (RelativeLayout) findViewById(R.id.display_prefs_dialog);
        prefsDialog = (RelativeLayout) findViewById(R.id.display_prefs_dialog_layout);
    }
    public void toggleIt(View v) {
        int visibility = prefsDialog.getVisibility();
        if (visibility == View.VISIBLE) {
            prefsDialog.setVisibility(View.INVISIBLE);
        } else {
            prefsDialog.setVisibility(View.VISIBLE);
        }
    }
}

XML: main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical" android:id="@+id/linearLayout1">
    <Button android:layout_width="wrap_content" android:text="Button"
        android:id="@+id/button1" android:layout_height="wrap_content"
        android:onClick="toggleIt"></Button>
    <RelativeLayout android:id="@+id/display_prefs_dialog_layout"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:visibility="invisible">
        <include android:layout_width="fill_parent"
            android:layout_height="fill_parent" layout="@layout/mainsecond">
        </include>
    </RelativeLayout>
</LinearLayout>

XML: mainsecond.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/display_prefs_dialog" android:layout_width="320dp"
    android:layout_height="480dp" android:background="@drawable/mainbg">
    <RelativeLayout android:id="@+id/display_letters_bg"
        android:layout_centerInParent="true"
        android:layout_width="250dp" android:layout_height="100dp"
        android:background="@drawable/databg">
    </RelativeLayout>
</RelativeLayout>

, , Java , - RelativeLayout.

0

All Articles