How to hide and show some elments in layout in android? - android

i'm trying to hide a linear layout at screen and it is some of the screen and if i use
android:visibility="invisible"
it take a space from the screen and i won't to be invisible and other element must show in the right sequence
is there is a method in xml to do that or in Java code ?

Set android:visibility="gone" or programatically setVisibility(View.GONE)

Don't know if I undestand what you're trying to do, but invisible will hide the element, but the element will still use up it's space. Use gone to completely remove the element.

You can change the visibility of the element either by XML or pro-grammatically
Via Program
TextView text =(TextView)findViewById(R.id.textView);
text.setVisibility(View.GONE); //Completely hide from container
or
text.setVisibility(View.INVISIBLE); //it occupy space and view will hide
Via xml
andoid:visibility ="gone"
-------->

Related

Android - Fading Layout Border

I am working on an android app and I have a scrollview, and in that, I have a linear layout in the main activity. I want to have the top and bottom borders of the linear layout to be "faded
" so as the user scrolls down the child views in the layout will "fade out" as the go down.
Here is an example of what I am trying to achieve in my linearlayout or scrollview (the "fading bottom border".
Thanks for you help!
Subby
You can do that by using the following attributes in the ScrollView.
android:requiresFadingEdge="vertical"
android:fadingEdgeLength="20dp"
If you want it on devices before API14, you need to use the following:
android:requiresFadingEdge="vertical"
android:fadingEdgeLength="20dp"
NOTE: This is actually discouraged as it is seen to have a negative performance impact on devices.
At the bottom of your layout, you can have a view above the listView, and set Gradient Color for the view, and also make it semitransparent, then you can have the effect you want.

How to add TextView at below in a RelativeLayout when there is no space at right?

I've seen many of questions for how to add TextView in a RelativeLayout programatically, but everybody adding it in LinearLayout with orientation vertical. Can any one suggest me or give me a link that how to add multiple TextView in RelativeLayout at right until it has space and then change the line.
I want a layout like this..
May be this works for you !
You can customize chips-edittext-library for your need. Customizing by setting background to transparent, and editable to false.
-> Or you can use any other library which is used for displaying emoticon in EditText and customize it according to your need. Like android-emoticon-edittext-spike
You can use the Flow Layout library that manages the view arrangement itself.
When there is no space left the added View is moved to the next line

Leave blank line in Linear Layout

I am developing for android. The app is designed in XML in Linear Layout. What I want to do is to leave some blank lines between the consecutive buttons/text to ensure some neatness in the GUI. Is it posible to do it in Linear Layout? Please help...
You should use margins to seperate different components in your layout. An example of how this would look in your XML is: android:layout_marginTop="12dp"
If you want to leave space outside the border of text/button and next view elements you can use android:layout_marginLeft, android:layout_marginRight, android:layout_marginTop and android:layout_marginBottom.
If you want to leave space between border of the text/button and actual content of the text/button you can use android:paddingLeft, android:paddingRight, android:paddingTop and android:paddingBottom.
For more info check out this question
how to increase the space between the elements in linearlayout in android?

How do I layout a button bar with buttons of different heights?

How do I go about implementing a button bar with buttons of different shapes and heights? As an example (please excuse my poor drawing skills for this quick mockup):
The example bar has 3 buttons, with the middle button (3) a different shape and height than the other 2 buttons (1,2). The button bar will be a view that is included and merged into other views so as to seem to float on top of the parent view.
I was thinking of implementing buttons 1 and 2 into a layout, and then button 3 as another layout that I then merge with the first two button's layout.
like my previous comrades said, you need some kind of layout or container that can have a background (if you wish for button #3 to hoover above it) then use relative layout for mixing the two the disadvantage of this other than complexity is that youcannot relate to the other two buttons since they reside in a different layout.
More elegant solution may be to have a special background drawable that can:
have a method setCurrentHeight() that will specify the height the actual viewable section should have the rest will be filled with transparent color.
override it's own draw so just before it's drawing it will have a callback called, call back you can register yourself to.
then you can register the callback in your activity to take the current position of the #3 button and set the height accordingly, this way you are still with one layout with special drawable as background.
A customized LevelDrawable might do the trick.
I would layout this bar as follows:
A RelativeLayout as a container for the rest, with height set to wrap_content and alignparentbottom = true
An ImageView for the bar
2 Buttons with a transparent background (Button 1 and 2)
Button 3 is a custom Button with a custom Image of a trapezoid as background
So you will have a Layout similar to this:
<RelativeLayout
...>
<ImageView
.../>
<Button
... Button 1 />
<Button
... Button 2 />
<Button
... Button 3 />
</RelativeLayout>
I don't exactly know that this will work, and I can't test it, but you might give something like this a try; I believe it can all be done elegantly through XML.
Have a RelativeLayout (id:mainLayout) that will contain all of your views, wrap_content for both dimensions.
Have a blank View as your first child that will serve as your background bar
Set the View's background color/image to what you want; layout_width to fill_parent; layout_height to wrap_content; layout_alignTop="#id/leftButton"; layout_alignBottom="#id/leftButton".
Add an ImageButton for your center button (id:bigButton), wrap_content for both dimensions; layout_centerInParent="true".
Add an ImageButton for your left button (id:leftButton), wrap_content for both dimensions; layout_toLeftOf="#id/bigButton"; layout_centerInParent="true".
Add an ImageButton for your right button (id:rightButton), wrap_content for both dimensions; layout_toRightOf="#id/bigButton"; layout_centerInParent="true".
In my head, I believe this works, but I could be off. Regardless, something to think about, and I hope it helps you find a solution. :)
Better you can tablelayout with different button styles or relative layout for button "3"

Android button dynamically placed on button

I wanted to know if there is a way to place a button on the bottom of the screen, no matter what size screen the device has. I basically want the button to have a gravity="bottom", not just its text. I have been trying to do this, and I cannot find a way to do it. any suggestions?
What layout is the button in? Using a relative layout, you can set the button to align_parent_bottom.
use a RelativeLayout with layout_height="fill_parent" then set the button's layout_alignParentBottom value to true in the XML file
Never mind, I created a child LinearLayout only for and I put
android:gravity="bottom"
in the child and it worked :-)
Try using android:layout_gravity="bottom" on the Button :)

Categories

Resources