Search code examples
androidxmloverlay-view

How to overlay a small view on a Main view without fully covering main view?


So I need the view of my settings to display over my main page.where there is a "setting"button in Main page which opens this settings view. But I want My main page to be visible beneath my settings view which only covers a half or less of the main view.

I tried adding

<org.example.myCustomView 
    xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    android:theme="@android:style/Theme.Dialog" />

Which I found from stackoverflaw itself. But I cannot do it instead the application corrupts at button click.

I am not sure I got this too correct, Or is there any other clear way to do it? I replaced myCustomView with my relevent class and created the manifest also but it did not work.

If there is any other alternative way to do this mention to me.

I am not talking about how to place a TextView, Button, EditText on a view

I am talking about completely two layouts.

Below image is only an example to express my question.

enter image description here


Solution

  • I think you need to utilize layoutinflater. Here is a simple example how to use it

         setContentView(R.layout.yourMainView);
         LayoutInflater mInflater = LayoutInflater.from(getApplicationContext());
         View overView = mInflater.inflate(R.layout.yourSmallView, null);
         addContentView(overView, new LayoutParams(LayoutParams.MATCH_PARENT, 
                LayoutParams.MATCH_PARENT));