Hide a certain element in XML preview but show it on device? - android

This is not a directly programming related question but I don't know where else to ask and I am running out of ideas where to look.
Is there a way to hide a certain element from XML preview but still show it when the app is compiled? I don't mean the "visibility" attribute. If you set visibility to gone, the device also won't show that view. What I want is to simply hide a certain element from xml preview.

You can hide it using the visibility attribute on your xml layout file, and show it programmatically at runtime.
view.setVisibility(View.VISIBLE);
EDIT
Apparently there's a better way of doing this, in case you're using Android Studio, as of v0.2.11 you can take advantage of designtime layout attributes, for example:
Include this in your layout:
xmlns:tools="http://schemas.android.com/tools"
Change visibility attribute:
tools:visibility="invisible"
Full example and documentation available here.

Related

android studio issue: complex Layout is not showing in design view but just as XML

I have a somewhat complex layout.xml file (353 xml lines, 16kb) with multiple nested constraint layouts. This particular xml file is only showing a blank white screen in the design tab but works well when I run it on device and emulator. I have other smaller layout files which show the design normally on android studio but it seems that there is a bug with viewing larger xml files.
Is this a known issue? I tried refreshing layout and removing android studio cache but nothing seems to work. any ideas?
I do not think it has anything to do with the code since it runs normally on device and I am not sure posting the whole xml file on SO is a good idea.
update
What I realised is that all the elements in the layout seem to be 'invisible' at the top left corner since when I hover over them the pointer turns into a hand and when I click , certain elements get highlighted in the component tree. This is a screenshot of what I am seeing:
I added android:visibility="gone" which is vital to my app. Little did I know that it also applies to the design view which I find to be really useless. I want the visibility to be gone during runtime, not on a platform where I am supposed to be tweaking the design of the UI. This is ridiculous to me.
Does anyone know If I can keep visibility="gone" but still see the design in the design view of the layout?
You can use tools:visibility="visible" for designing purposes.
It has zero effect on the view in real use.
Don't forget to keep your android:visibility="gone".
In general, use tools attributes whenever you'd like to manipulate a preview in the designer while keeping your view attributes valid for real use.
Edit:
Keep in mind that there is a huge difference between invisible and gone. More about that

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);

Tips at start-up or update

I have an update for my app that includes ActionBarSherlock with a sliding menu. I have put my navigation entirely in to the sliding menu, leaving my main_activity pretty bare. I am worried the user won't know about the menu. So I want to add a prompt at start-up that will highlight the new feature. Like this:
I am not even sure what this is called, so I don't know how to research it. Any help or suggestions will be rewarded. Thanks!
You could just use overlay layout (Frame layout with multiple inner layouts will fit perfectly. Please note Frame Layout Z axis is by the lower the layout is in the xml, so the guide should be the last in the XML). Make that layout's background mostly transparent and add buttons and design to fit your needs. When you don't want to show the layout just set visibility to gone. And when you need it set to visible.

control for multi facet popup screen in android

I want to create a popup screen with multiple views, just like home screen but as a popup. As I am relatively new to android, so I am not aware if any such control is built in or do I need to use any library? or any hint would be helpful.
EDIT: I am looking for an alternation to viewpager, which is supported minimum on API8.
It sounds like a PopupWindow may be what you're looking for. Added, in API 1, this let's you add a View(s) dynamically or you can set the layout to an already created xml file.
A popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity.
You also can create an Activity with whatever Layout you need in xml and give it a Dialog theme to make it look like a pop up by setting the
android:theme="#android:style/Theme.Dialog"
in the <activity> tag of the manifest
I found the answer from the comment #codeMagic's comment below his answer, so posting here for the reference:
for ViewPager alternative we can use ViewFlow or ViewPagerIndicator library, there minimum supported SDK are API level 1 & 4 respectively.

Section Header using Android XML?

enter code hereLooking through the Android UI guidelines I came across this section / example:
In the example above, there are a few headers called 'SECTION' with a horizontal line underneath them.
Im still getting grips with the appropriate way to replicate this -
Is there something specific like a Header XML element to use that will automatically style the font and horizontal line? Or is something like this generally more primitive, i.e. A TextView with a 1 pixel horizontal image (ImageView?) underneath it?
Possible duplicate question of this one: Android 4.0 Sub-Title (section) Label Styling
In short: try adding attribute style="?android:attr/listSeparatorTextViewStyle" to the TextView element, which you wish to make look like that, in the XML layout file.

Categories

Resources