"Empty" container to set as another UI element's parent - android

I'm re-writing my app with this layout in Android (using Android Studio 3.6 & Java 8) and noticed that I can't directly set the background color of an EditText or Spinner because the background used contains the e.g. EditText's line (the line the text is written on).
To work around that in my iOS app I simply gave that UI element (with an otherwise transparent background) a View parent that uses the right background color. In Android Studio this works the same way if I use an e.g. LinearLayout as parent but I don't need that layout's full functionality and I'm worried that "abusing" LinearLayouts like this multiple times might affect performance.
There is a View widget in Android Studio but it's not possible to add an EditText or Spinner as its child.
Are there any layouts/views that can be added via Android Studio's UI builder or through xml and that act as the "empty" container I need? What's the best layout to use performance-wise?

Related

App doesn't format elements at all & just shows them all in one line

I just downloaded Android Studio and decided to try it out, never programmed in Java, or any kind of android app. It all seems good but once I emulated the app. I got weird formatting that wasn't a thing in app preview when I coded it. This is a simple "squaring" function app.
When I look at the preview:
When I emulate it:
You are getting this kind of formatting because you are using Constraint Layout as your root layout. There are no constraints to the views(EditText, Button and others) because of which they are placed at the top left corner of the screen.You have to add constraints in ContraintLayout.
Follow any of the three methods below-
Learn about Constraint Layout. Check out this link -Build a Responsive UI with ConstraintLayout in Android Studio (Most Useful of the three)
Change Constraint Layout to Linear Layout or Relative Layout as your root layout.(if you are familiar with them)
Click Infer Constraints (orange color two stars type symbol ) to automatically create constraints and compile again.(Simplest of the 3 methods for you right now)

Fake LinearLayout content on Design Tool with Android Studio

Is there a way to fake the content of a LinearLayout (or any other layout) just for design purposes?
I have a LinearLayour inside an HorizontalScrollView. I add some ImageViews programmatically inside the LinearLayout because I get them from a web service. But I'd like to see the final output on the design view of the layout so I don't need to run the app every time I need to see some images there.
Is there a way, using the tools namespace (or any other trick) to show some ImageViews inside the LinearLayout only when using the design tools?

android lollipop ViewGroup child hierarchy changes?

I have an app that has a minSdk of 15 and I'm working out all the bugs that came with the lollipop upgrade. Our software is very complex and it dynamically creates views using custom ViewGroups and then an array of elements that are explicitly sized and placed inside the group. I'm running into an issue where for example I'll have a ViewGroup and the first child object is a Button...this button is sized to fill the view (not clickable). The second child is a FrameLayout containing a single view. This single view is a video object. In all prior versions of Android this works just fine. The FrameLayout is layered over the button (that is acting as a background) and the video is inside the framelayout. You can interact with the video without any issues.
Something changed in lollipop - suddenly, even though the button is showing up as the 0 index element, it is laying OVER the rest of the children...so I cannot get to the video underneath. If I remove that button element, the video renders and plays just fine...I have no issues interacting with it.
I ran the app in UI Automator Viewer just to make sure I was really setting up the UI as I expected (keep in mind the entire view is dynamically rendered at runtime using image/video assets and xml config files).
I'm not able to share code since this is proprietary software, but I am working on a little test project to see if I can manually recreate the issue with static objects. Once I get that up and running I'll be sure to update this ticket. For now, here is a screenshot of the hierarchy:
https://goo.gl/photos/a8on9CJDnN66XYnV6
Notice the highlighted object, this is the custom ViewGroup, the children below it are what I am describing above.
Does anyone know of a change in Lollipop that would effect the ordering of things? I found earlier that if you have a disabled object but don't have a disabled state drawable assigned to that object it would become invisible, previous versions just used one of the other state drawables..okay that makes sense and it was very easy to fix, but this object is not invisible...so it must be something different.
Any direction would be greatly appreciated.
~A
UPDATE -- FIXED
With the help of #alanv and #BladeCoder I figured out this functionality was due to the new elevation feature of Material design. I was able to fix my particular issue by first checking what version of android the device was using, and if lollipop, I just add this new property to the button:
android:stateListAnimator="#null"
This prevents my explicit child hierarchy from being overridden by the OS.
Lollipop introduced elevation as a way to position the elements on the Z axis and cast shadows between them depending on their difference of elevation.
Enabled buttons have a default elevation of 2dp (and it increases when you press them). So, your button has a higher elevation than the FrameLayout (0dp by default) so it will be drawn on top of it.
Disabled buttons have an elevation of 0dp. That's why disabling the button solved your issue.
Using buttons as backgrounds looks like a bad idea (why not setting a custom Drawable background on your FrameLayout instead?) but if you really need that, you can disable the button like you did and, just to be sure, enforce its elevation to 0dp. Another workaround is to increase the elevation of the FrameLayout but then it may cast a big shadow under Lollipop if it has a background, and maybe that's not what you want.
Okay, UPDATE! I figured out how to fix the issue, although I'm still not sure (even after pouring over the diffs between several classes in grepcode) what changed in lollipop that is causing a change in how this works.
If the button is enabled...and you are placing it using something equivalent to AbsoluteLayout (We have our own ViewGroup we created called Explicit layout, but it does pretty much the same thing as AbsoluteLayout), it will always be on top of anything else in the stack that isn't also a button of some sort (at least that's what I'm finding...I didn't test through every possible widget).
Setting the button that is acting purely as a background image to enabled=false solves this issue. I know, it doesn't make sense that we use Buttons as background images, but our code uses it for dynamic element creation so there are many possible states and uses for each element.
Anyway, not sure if anyone else would even run into this issue, but just in case you do...here it is.
Thanks!

Are there debug XML tags for the ADT layout editor? E.g. to make collapsed views visible in preview

I want to have collapsed views (with Visibility=GONE) to be visible while using the layout editor of ADT.
Are there any debug xml tags to show the layout in preview differently than in the running app? I remember seeing them on Microsoft XAML.
I intented to use this workaround, however the app crashes then while inflating the layout: I set up a string resource with the value of either "gone" or "visible". The visibility attribute of all collapsed views refer to this string resource. Now I have only one place to set the visibility of all that layouts.
You could use isInEditMode() in a custom layout class, to see if the layout is being rendered as a preview, in an IDE.
However a much easier solution would be to keep it visible and just programmatically set it to GONE, once the layout is done inflating:
findViewById(R.id.container).setVisibility(View.GONE);

Eclipse not showing colored textview in Graphical Layout

I am using Eclipse with the corresponding Android SDK and plugin to develop Android applications.
When editing a layout I am presented with both an XML view and a Graphical Layout view for the layout. In my layout I have several TextView controls/views.
By default they display with the black foreground color which is just fine. However, my application uses some predefined colors (foreground) for some of these views. For that I have defined the colors in the XML so that I can select them in the Text Color property of the IDE.
The issue arises when I try to use the Text View property of the Eclipse IDE to change the default color of the TextView. As soon as I select a color (for example #color/red) then the foreground color of the TextView is always changed to WHITE regardless of which color I chose, even with Black it becomes white.
Now that seems to me like a problem. Am I doing it correctly?

Categories

Resources