Is it possible to "collapse" (in my case, width=0, and the element to the left of it will expand and take its place) an element (in my case an ImageView) in Android ui when it's been set to invisible?
If you are using the right layout, you can apply a positive weight to both elements with layout_width=match_parent. Fiddle with the weights until they look right.
When you want one to disappear just call .setVisibility(View.VISIBILITY_GONE). The element will vanish and the other one will fill the missing space.
Couldn't you just use setVisibility(View.GONE)? That will make the view take up no space and other views will take up the space it occupied.
try to remove the old version of view and instead of that one add a new one
RelativeLayout item = (RelativeLayout)findViewById(R.id.item);
View child = getLayoutInflater().inflate(R.layout.child);
item.addView(child);
Related
I would like to know which is more profficient way of placing children in RelativeLayout. There are two approaches of doing this:
1) Place the main view with absolute position (like layout_centerInParent or set margins/paddings correspondent to parent view) After that you add other views and set them attributes like android:layout_above="#id/relative_view_id" and place them below relative view. It is not good way because your views hierarchy in xml does not match to what you see in preview.
2) You assign to children of RelativeLayout attributes with absolute id android:layout_above="#+id/relative_view_id" (+ appeared). It provides the correct views order in xml. BUT when you looking for declaration of view with relative_view_id from java code (by pressing cmd+B) Android Studio suggests all the views where you declared #+id. In our case View with attribute android:layout_above="#+id/relative_view_id" will also appear in search results.
What is your way of placing Views in RelativeLayout?
android:layout_above
Positions the bottom edge of this view above the given anchor view ID.
Accommodates bottom margin of this view and top margin of anchor view.
For your question I would prefer No 1 way .
android:layout_above="#id/relative_view_id"
Its refer the already generated id (relative_view_id) .
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
I'm adding 2 different views in my ListView header view but for some reason it create a 20dp space between those 2 views. How should I remove it?
Thanks!
Edit : The 2 views I add don't have any top/bottom padding or margins, I'm asking if there is any special "feature" in the ListView headerView about space/separator between views.
Edit 2: it seems that the space between the view in my header view is tied to the dividerHeight parameter. Why? I mean it should only be applied as rows separator. Is there any way to remove it from my headerView and keep it as actual row separator ? headerDividersEnabled=false don't do anything.
try to set android:headerDividersEnabled="false" in the ListView
i have same issue i have added dynamic header to listview but on the start of activity it gives space on the top of headerview and we scroll listview then header view overlaps with it instead of going up.
I'm developing an android app with fragments. While most of my layouts are pre-determined in the XML, I would like to programmatically insert a new view between views that were already loaded in a LinearLayout at startup.
How do I go about with this?
Thanks
Its possible to specify index while u dynamically add a view to a LinearLayout.
Set height of the first view as
android:layout_height="0dp"
android:layout_weight="1"
Set height = wrap_content for the second view in XML
Then while u are adding new View dynamically, set its height = wrap_content and add it to the parent LinearLayout like this
parentLinearLayout.addView(childView, index);
//index = position where you want to insert the new view.
It might help you. :)
the red View should have the default setting View.setVisibility(View.GONE) right at the beginning. When its time to show up you can switch over to View.setVisibility(View.VISIBLE). I cant verify the solution right now, but it should do the trick. So in this case you are not inserting a new View but make an existing one visible.
I want to layout my views in the following way: [Button] [SomeView] [Button]. I want to set specific sizes for buttons (in mm), and then have the SomeView fill the remaining space between them.
How to achieve this?
Maybe you could set the layout:weight of the [SomeView] to 1 and put all of these views in a linearlayout. Hope it works!