Does Android overlook everything?

Can you put an inscription on top of everything in android?

On the iPhone, I would get a new view by setting its frame.origin to (0,0), and its width and height in width and height in self.view . Adding it to self.view will cause it to act as an overlay, covering the content (or if it has a transparent background and then shows a rear view).

Is there a similar technique in Android? I understand that the views are a little different (there are three types (or more ...) relativelayout, linearlayout and framelayout), but is there a way to simply overlay the view indiscriminately?

+61
java android layout view
Sep 22 '11 at 17:47
source share
5 answers

Just use RelativeLayout or FrameLayout . The last child view will override everything else.

Android supports a template that Cocoa Touch SDK does not support: Manage layouts.
Layout for iPhone means position absolutely (except for some strech factors). The layout in android means that the children will be placed relative to each other.

Example (second EditText fully covers the first):

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/root_view"> <EditText android:layout_width="fill_parent" android:id="@+id/editText1" android:layout_height="fill_parent"> </EditText> <EditText android:layout_width="fill_parent" android:id="@+id/editText2" android:layout_height="fill_parent"> <requestFocus></requestFocus> </EditText> </FrameLayout> 

FrameLayout is some kind of view stack. Made for special occasions.

RelativeLayout quite powerful. You can define rules such as "View A" to align the parent layout at the bottom, "View B" should align from bottom to top, etc.

Comment Based Update

Usually you set the content with setContentView(R.layout.your_layout) to onCreate (it will inflate the layout for you). You can do it manually and call setContentView(inflatedView) , there is no difference.

The view itself can be a single view (for example, TextView ) or a complex layout hierarchy (nested layouts, since all layouts are the views themselves).

After calling setContentView your activity knows what its contents look like, and you can use (FrameLayout) findViewById(R.id.root_view) to get any view in this hierarchy (General template (ClassOfTheViewWithThisId) findViewById(R.id.declared_id_of_view) ).

+86
Sep 22 '11 at 17:55
source share
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/root_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:id = "@+id/Everything" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!-- other actual layout stuff here EVERYTHING HERE --> </LinearLayout> <LinearLayout android:id="@+id/overlay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" > </LinearLayout> 

Now, any view that you add to LinearLayout with android:id = "@+id/overlay" will be displayed as an overlay with gravity = right in a linear layout with android:id="@+id/Everything"

+12
Apr 07
source share

You can use bringToFront :

  View view=findViewById(R.id.btnStartGame); view.bringToFront(); 
+8
Jan 05 '17 at 18:14
source share

The best way is ViewOverlay . You can add any drawn as an overlay to any view as your overlay with Android JellyBeanMR2 (Api 18).

Add mMyDrawable to mMyView as an overlay:

 mMyDrawable.setBounds(0, 0, mMyView.getMeasuredWidth(), mMyView.getMeasuredHeight()) mMyView.getOverlay().add(mMyDrawable) 
+3
Dec 05 '16 at 9:02
source share

I already tried awnsers, but it did not work. Now I used LinearLayout instead of TextureView, now it works without any problems. Hope this helps some others who have the same problem. :)

  view = (LinearLayout) findViewById(R.id.view); //this is initialized in the constructor openWindowOnButtonClick(); public void openWindowOnButtonClick() { view.setAlpha((float)0.5); FloatingActionButton fb = (FloatingActionButton) findViewById(R.id.floatingActionButton); final InputMethodManager keyboard = (InputMethodManager) getSystemService(getBaseContext().INPUT_METHOD_SERVICE); fb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // check if the Overlay should be visible. If this value is false, it is not shown -> show it. if(view.getVisibility() == View.INVISIBLE) { view.setVisibility(View.VISIBLE); keyboard.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); Log.d("Overlay", "Klick"); } else if(view.getVisibility() == View.VISIBLE) { view.setVisibility(View.INVISIBLE); keyboard.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY); } 
0
Aug 09 '17 at 18:31 on
source share



All Articles