I have a relative layout tree, let's say that I have a couple of buttons in root layout and other one is placed on top of the buttons, covering them with it's backgound.
Visually everything is ok, but I still can activate invsible buttons placed under the layout, is there any property related to this?
I have tried elevation, translationZ, etc. I would like to avoid programatically fixing the problem (isShown for example), is there anything else I can change in xml to prevent them from activating?
In your layout xml file, add setClickable="true" to the same layout you've set the background to.
Related
Let's say I've got a whole interface with some Layouts, View-Objects and stuff and now I want to write a java method that adds a pop-up error message over all this layouts to the front.
I know that there is the possibility to add it to an existing layout (e.g. main_layout) this way:
main_layout.addView(error_layout);
But is there maybe a way to put it just independent from the other layouts on the interface?
Something like
UInterface.addView(error_layout);
?
This should give you the root layout of your activity
getWindow().getDecorView().findViewById(android.R.id.content)
I'm trying to create my android app for a lot of different devices so I'm trying to avoid using fixed heights and width and instead using the property WRAP_CONTENT.
Now I need to create a textview on top of a button and align that to the bottom. However the documentation states that you can't use WRAP_CONTENT in combination with ALIGN_PARENT_BOTTOM (which is obvious). Is there another way to achieve this?
The structure is something like this. A RelativeLayout which wraps a button and a textview.
RelativeLayout fl = new RelativeLayout(this);
fl.setLayoutParams(relativeWrapContentParams);
fl.addView(filterBtn);
fl.addView(filterCaption);
The buttons are also created dynamically so theres no xml. Instead the buttons are created in java code.
Also is this a good way of programming for multiple resolutions? Or is it ok to use fixed heights because then the problem is easy to fix and I can just give the relativelayout a fixed height and align its children with ALIGN_PARENT_BOTTOM
See this link this article is the bible for the newbies in android.
Now coming to your question you don't need to use relative layout just for this purpose
you can use linearlayout with vertical orientation place text and then button.
and you need to place this linearlayout inside relative layout with property alignparentbottom=true.
in such way you can have this layout of text and button at the bottom of the screen
In my project i have 3 xml files.
My main layout
and 2 layouts which i want to include in my main layout
*big_buttons.xml* >contains big size buttons
*small_buttons.xml* >contains the same buttons as above (same id's aswell) but they are smaller
By default i want the *big_buttons.xml* included, but id like to be able to "exclude" the *big_buttons.xml* and include the *small_buttons.xml* programmaticly after an onClickListener
Is it possible to do something like this?
By default you can use setContentView(R.layout.big_buttons);, and then in your onClickListener you could do setContentView(R.layout.small_buttons);
If it's specific buttons you want excluded rather than the entire XML, I think you need to combine the 2 XML files and by default give the "big buttons" the attribute android:visibility="visible" and the "small buttons" android:visibility="gone".
Then programmatically you can do
Button bigButton = (Button) findViewById(R.id.big_button);
Button smallButton = (Button) findViewById(R.id.small_button);
bigButton.setVisibility("View.GONE");
smallButton.setVisibility("View.VISIBLE");
You'll want to use GONE rather than INVISIBLE because GONE excludes layout features like height and width, where INVISIBLE just doesn't display the button, but keeps space for it.
Check out View.setVisibility. You can use this on a layout manager, so that you can make entire groups of controls visible or invisible from Java code.
Is there a way to bypass the layout manager for a given component in Swing? Something similar to position="absolute" in CSS. Null layout is not an option.
I have an existing GUI which I can't modify and uses different kinds of layouts and I need to add a button a the top right corner of the screen.
If you can't modify the existing GUI, including the top-level containing JFrame, you might be out of luck.
If you can modify the root container, you can achieve what you want with a layered pane. You can put your existing JTabbedPane in a lower layer, and add your button on a higher layer (and there you can use a null layout + setLocation()).
i have four images in a row at the top , on click of each icon i want to change the underlaying background (image) and the controls on the layout , this way it achieves tab like structure and behavior , i want to know whats the best way to achieve this ? I think i will have four layouts each layout having one image highlighted showing that tab selected and corresponding components on layout, and will change this layout when user clicks on image.
Is this a good idea to achieve this ? or i have different solution available ?
its nice if u give me some idea about necessary features or API or layout component related code
Suggestions are welcome thanks!
That is not a good idea. You should use android's tab architecture. Here is a example at developer.android
you can change layouts by switching views to invisible and visible. but it's not a good idea when you want to change 4 layouts.
It becomes hard to maintain the code if you have 4 layouts switching.
It's better to use Tabs which will help you in preserving the state of the each layout.
Customize the tabWidget to make it look like you have 4 buttons on the top, not the tabs.
HTH.