Using ViewSwitcher with Eclipse IDE - android

I am new to android programming, and I am using eclipse.
I am using ViewSwitcher, and able to switch back and forth between views.
My question is with eclipse.
In eclipse, how can I edit the different layouts graphically? Only the first layout is visible when I select the res->layout->main.xml.
I know there is a work around (or may be even the right approach); having two layout files, and switching between them. But that is not my intention right now.
Thanks for any suggestions.
Karthik

Its a bit late but I had the same problem and got around it with only xml changes by putting the contents of the 2 layouts in other files and including them in the original file. Not sure if this is proper but it made it easier to test.
<ViewSwitcher
android:id="#+id/detailSwitcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include
layout="#layout/layout_file_1" />
<include
layout="#layout/layout_file_2" />
</ViewSwitcher>

I would not create a view graphically. It is really easy to type in the XML and then you know you are making exactly what you want. Use the GUI to check your work. I would certainly build the two layouts in separate files and then paste them into the one with the view switcher when you have it just as you want it.

You just have to change the sequence of the layouts in the view switcher. The first layout in the viewswitcher is visible in eclipse. Edit your first layout which is in the viewswitch and then move the second up to work on it.

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

Adding elements to the layout?

I had this question earlier today, and have been stuck on this for 3 hours!
The answer suggested that it is okay to remove the activity_content as long as I remove the line:
<include layout="#layout/content_menu" />
I did that...And started to edit directly in the layout, after copying the default contents of content, except...the layout isn't even there when editing! So, am I supposed to keep both layouts, and just edit the content one? Why do I even need to do that? Is there a reason for this update in android studio?
I'm just creating my activities like this:
yes you can just leave the activity_yourclassname.xml as it is and make changes to content_yourclassname.xml only for the main content.
and yes this update is made just to make code more cleaner and more reusable. so that you could focus only on the main internal content of the code without getting into complex layouts.

setting my main project default to linear instead of relative

Everytime I follow a tutorial book or you tube video, I have also used the cheat help in eclipse. My programming always comes out with errors. here is one example why does all the tutorials main activity comes out showing linear layout and my projects default is relative layout. So how do I change the default to linear when creating new project.
I know I can open a new layout xml but all the tutorials opens a new project in linear.
I am a massive fan of android and I really want to make some apps, but all the tutorials never seem to correspond with the results I get and they all make it look so easy.
go to youre layout.xml
make sure to be in the graphical layout (check bottom bar)
top-right in 'outline' right-click on the relative layout
choose 'change layout'
choose youre desired layout, (linearlayout(vertical) probably in ur case)
I found it after digging a lot in Android Studio After visiting JetBrains and Intelij documentation and help sections i found nothing much helpful but i found way on my own, I had answered it here, With all explanation and screenshots.

Design tabhost in Eclipse

I have a question that I think is really easy answer if you know, how to I change the visible tab in Eclipse while developing the GUI in Ecplise?
I can add tabs and add stuff to the outline and change it but I can't figure out how to change what Tab that is visible in the development view, I can only see the first tab...
(If I move the tab I'm about to develop to first position the I can see you not the right way I guess?)
Have search google and forum but no luck so far.
Thanks in advance
Best regards
Oskar Norin
Sweden
The only way I can see of how to go about doing this is to create each tab in its own xml layout file and then join them together using the include tag in the xml to link to that tab.
Something like:
<include
android:id="#+id/tab4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="#layout/tab4" />
This way you just switch to the layout you want to design and it gets included automatically. Not ideal but it works.

Possible to rename widget after laid out in RelativeLayout?

Working with Android for the first time, I've blocked out a layout using the relative layout and laid down some buttons and text widgets how I like them. However when I go back to rename the IDs the layout goes all crazy moving elements around and in general destroying the hours of work I spent laying them out.
Does anyone know how I can rename the widgets without Android destroying the positioning for widgets in the Relative Layout? Is this some "feature" of Android? I can't imagine why it would be hard for the UI builder to handle simple renaming of a widget ID without destroying the positioning information.. Do I have to use an external text editor and modify the XML files directly? Ughh I hope not.. I'm using Eclipse IDE.
You can use find and then replace all to change the names every place that they appear. Shouldn't take anywhere near an hour if you're dealing with a small layout.
In general the graphical UI creator that is currently included with the Android SDK is not so great for creating anything but very simple layouts. In my experiences (which were a long time ago, it may have gotten better since) it was terrible with RelativeLayouts.
If you have not modified your xml directly then it is time that you jump in and start learning to do it that way. You'll find that you have a much greater level of control over your layout, and once you get the basics figured out you'll probably be able to create quicker using raw xml then with the graphical tool anyway. I do wish that there were a nice GUI creator for android out there, the best one that I've ever come across is Droid Draw which I found to be better than the one included with the SDK, but still not as good as I was hoping.
To modify the xml directly you don't need any additional text editors, you do it inside eclipse. Open up your layout file and at the bottom click on the tab that says "Source" when you want to switch back to graphical (good to see the changes that you make to the xml graphically) just click back to the tab that says "Design"

Categories

Resources