I have a LinearLayout called mySlab inside another RelativeLayout. I need to make the mySlab and its children views transparent programmatically. Do I have to make each child transparent explicitly or is there a way such that if I turn mySlab transparent the children will follow?
A bit of clarification
The layout view in question has a number of children each with its own color or image background. I am hoping to be able to dial the transparency of mySlab without actually changing the colors and backgrounds of each child per se. iOS does that very well.
Also mySlab is actually a RelativeLayout, not Linear, though I don't think that should matter.
its easy in android, use this property
android:background="#00FFFFFF";
where 00 is for tansparency, and rest for rgb color.
Have you tried this:
LinearLayout ll = (LinearLayout)findViewById(R.id.myLayout);
for (int x=0;x<ll.getChildCount();x++)
ll.getChildAt(x).setBackgroundColor(Color.TRANSPARENT);
ll.setBackgroundColor(Color.TRANSPARENT);
this will change the LinearLayout and its childrens
Related
I have a relative layout with child TextViews.
The background of the parent RelativeLayout is white and I was wondering how I could change the alpha to change the opacity of the whole view programmatically (including children).
I am trying:
getBackground().setAlpha(0.4);
But that expects an int and not a float.
If I do:
getBackground().setAlpha((int)(0.4 * 255));
The latter changes the view but makes it darker than I want. Also the children do not seem to change. It seems to affect only the background while I want something that makes everything more "grayed" out/less transparent.
What am I doing wrong?
Have you tried using android:background="#88000000" in layout file. You can change alpha and color values as required.
That's because you are changing the backgound of the layout and not the layout itself. So instead of myRelativeLayout.getBackground().setAlpha(), use this: myRelativeLayout.setAlpha(0.4f).
i am getting "Set android:baselineAligned="false" on this element for better performance" while using LinearLayout, I know its regarding performance,but i dont know exactly why it is,please clarify me
If you are looking for a visual explanation like me, then you might find this useful.
When baselineAlign is enabled(i.e if it is set to true), then all the text in that line will be aligned to have the same baseline.
Note: By default, baselineAligned is set to true. (i.e. baselineAligned=true)
When you make baselineAligned=false, all it needs to do is to add new elements to the linear layout and be done with it. The app need not worry about where the baseline of other elements in the layout is.
See the image below for more clarity
android:baselineAligned/setBaselineAligned(boolean): When set to false,
prevents the layout from aligning its children's baselines.
So can take example with linear layout with horizontal child views having multiple TextView with different text size or different views like button there basealignment would be different and you cannot adjust it to have same basealignment if you set it to false
Reference
Update:
By setting android:baselineAligned="false" , you're preventing the extra work your app's layout has to do in order to Align its children's baselines; which can obviously increase the performance. (Less unnecessary operations on UI => Better performance) as mentioned here
I want to create zig-zag layout same as following attached image:
I tried a lot by creating diagonal lines and arranging them with icon but couldn't make it same.
I implemented diagonal lines with the help of accepted answer from following questions:
Diagonal line across view
How rotate line in Android XML?
However I'm stuck to arrange lines with icons exactly same as in image.
I created this custom ZigZagLayout.java file to cater your requirement. You just have to update the package name in the 1st line.
It basically extends RelativeLayout, so you can use it in your layout-xmls just like any other ViewGroup class. Once you have instantiated this layout, just add child-views to it like it is done for RelativeLayout via addView(View child).
Example code snippet with dynamically created view:
ZigZagLayout zigZagLayout = (ZigZagLayout) findViewById(R.id.layout_zigzag);
Button btn = new Button(this);
btn.setText("Test Button");
btn.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
zigZagLayout.addView(btn);
I've also added few interfaces to this ZigZagLayout for your easy interaction like ability to set the connector-line stroke width, visibility, color, margins, etc.
Try it out and let me know if it suffices your requirement. Cheers.
If you have layout for each circular item , you may use relative layout to align them, using align_below, align_left with margin, align_right with margin tags.
Please provide further detail, what are the lines connecting them and exactly what all are requirements for UI and functionality.
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 have read many question on this topic but found no answer.
the problem is that I have a ScrollView as mainView in my xml and if I set a background it is stretched.
ScrollView(background)-->content
I also tried:
Scrollview-->content(background)
To solve the issue I need to wrap the scrollView inside a LinearLayout.
LinearLayout(background)-->ScrolView-->content
Now the background (if applied to the mainLinearLayout) is no more stretched but I have the warning:
This ScrollView layout or its LinearLayout parent is possibly useless; transfer the background attribute to the other
view
I'd like to have the background not stretched and also get rid of this warning.
Probably I've not fully understood how this Views work...
Thanks for your help
Not a beautiful answer. But it should work.
You can set the background activity in styles xml file.
Remove useless LinearLayout.
Set the background of scrollview to transparent.
in your first case, use android:layout_height="wrap_content" for the scrollview and it won't stretch the background picture anymore