Android: How can I create a layout within a layout ? - android

In my app I want to have a button that if the user clicks it
than a new layout is opened within the current (acually the main) layout.
the new layout should not fill all of the screen and parts of the previous layout
should be grayed out.
Any ideas on how to do this ?

You can show a hidden layout within your button's onClick event by calling
view.setVisibility(View.VISIBLE)
You can also fade out view elements or whole views with
view.setAlpha(75);
view.setBackgroundColor(Color.GRAY);
Note that "view" in the first example is your layout element.. LinearLayout, RelativeLayout, etc. and in the 2nd example, "view" is the element(s) you're trying to gray out.

Follow the answer of SBerg413. And for more information. you can take the relativelayout for the part that you want to hide and display on the button click.
And as like SBerg413 answer. you can hide the respective layout and show the layout you want to display.
Hope it will help you.
Thanks.

you can use a ViewFlipper to achieve what you want, position the viewflipper where the child views should fit (part of the screen you say)..
Inflate the rest of the "child" layouts from other xml, add them to the flipper and switch between them when you want...

Related

Horizontal Bar in Android

This is my first time when i am posting on a forum. Although i am using stackoverflow for a lone time and find it useful.
My question is that i am developing a virtual chemist laboratory! and i have to make a horizontal bar upon which different apparatus can be placed like shown in the picture. Please tell me how to achieve that
Use LinearLayout and set orientation to horizontal.
Inside this layout add images as much as you wish.
Use weightSum for linearlayout, also use layout_weight for all images.
this can be done by FragmentActivity put horizontal button in main layout and replace fragment
firstly create a fragment main layout which has two Items ur horizontal buttons and container for replace fargment then create fargments according to ur button if u have 4 button the create 4 child fragmentss *
check my project
You can instead use horizontal list view. Its just a simple list view with same adapter support to form list in horizontal orientation.
Check the link for reference https://github.com/sephiroth74/HorizontalVariableListView
Done with this problem using Linear Layout. and then using a customized border on the bottom side. Then just add horizontal scrollbar in it.
Link : https://dl.dropboxusercontent.com/u/54327753/Screenshot%202015-01-02%2022.23.17.png

Display rest of layout fields on button click on same View

I have layout containing 30 fields ( using editbox, spinners, buttons etc)
but it looks too weird with crowded elements. ( scroll view is also longer)
So i decided to keep 1 more button, so firstly 15 fields will display and 1 "More" button below,now i want to display rest of fields onClick "more" button on same layout ( below that 15 fields). How to do this, thanks in advance
I would suggest you to make a parent view with two main relative layouts. First relative layout for all the content you want to show at first time. Make this layout visibility View.VISIBLE. Second relative layout for all the content you want to show on click event. Make this layout visibility View.INVISIBLE.
On button click event make second relative layout visible by setting view.setVisibility(View.VISIBLE)
Don't forget the invisible the layout in the end. Otherwise it will be visible throughout the app session.
You can also set this property in your xml too. There is a android:visibility="visible" tag in every view.
This approach will help you in management because by setting a single view visibility you can manage your all view. Happy Coding!!

How to have two layout xml files in a single activity in android

I am developing application in android.What I want is ,my activity should represent two xml layouts files.concept is like,
->when the activity is started it should show one layout(screen)
->when I click on the button exist on the first layout, it should show 2nd layout in the bottom of the screen,keeping first layout visible.
Have both the layout in a single XML. Keep the visibility of the the second layout to secondLayoutObject.setVisibility(View.GONE) initially and then on the click of the button change its visibility to secondLayoutObject.setVisibility(View.Visible).
On method to call two xml files in on activity is by using layoutmanager and assign the screen ratio for both xml files. Use relative layout in both xml. Small code snippet is
RelativeLayout layleft = (RelativeLayout)inf.inflate(R.layout.firstxml,null);
RelativeLayout layright = (RelativeLayout)inf.inflate(R.layout.secondxml,null);
for detail info Layout Reuse help
For this you have to use the concept of visibility. Initially set visibility of second layout as GONE and when you press button set Its visibility True.
you can try use the bellow example:
https://github.com/AdilSoomro/Iphone-Tab-in-Android
this source code to change layout like button click to load another layout!

How to show and hide layout dynamically

I want to make layout that expands dynamically, like some kind of menu.
It should look like this
http://imageshack.us/photo/my-images/845/dialog.jpg/
Step 1:
When I click on TextView it should inflate the new layout, remove transparent one, and move text to the left side.
Step 2:
When I click again on TextView (it's vertical custom TextView btw) it should go back to Step1
I want to put this layout into custom dialog and it should always be on my right side of the screen?
Any ideas how to solve this?
I can do this with two layouts and changing contentView of dialog on every click, but it seems like a very dirty solution. Is there some nice and fancy way to do this?
The simplest solution is probably just inflating all the Views, set their visibility accordingly, and move the TextView when the user clicks on it.
From the looks of it, it seems like you want to slide between a lot of views by clicking the TextView? If so, you might want to look into something called ViewPager, with a little customization you might be able to archive that.
Create two different layout's mentioned in images like 1) layoutone.xml 2)layouttwo.xml
Now crete on linearlayout in add that layout in your alertdialog. Also add layoutone in that linearlayout by inflating that layout. Now on click of that textview just removeallviews from that linearlayuout & inflate second layout & vice varsa.

Nested text view in android,with dynamic content

I want to display a recursive or nested text view at depth of 3 in Android.The text to be displayed is, dynamic coming from web service.
for example:
If I Click on Help(Level 1)
it'll show topics under Help
If I Click on Help_Topic_1(Level 2)
it'll show questions under Help_Topic_1
If I click on this question, say HT_Question_1(Level 3)
it'll show Answer of that question(Level 3)
how to accomplish with this? please guide me.
You should use ExpandableListView. Reference http://developer.android.com/reference/android/widget/ExpandableListView.html
You can call expandGroup and collapseGroup methods for expanding and collapsing on clicks.
the simplest way to do this is to have a nested layout structure. Your root view will contain the button to show level 1 and a child layout and initially be visible. The children's layout visibility will initially be set to "GONE". In the onclick listener for each button you change the visibility of the layout below it to view to "VISIBLE".
This of course is a very simple way of doing it. If you require to have open and close animations you'll need to use a more complex method.

Categories

Resources