I am creating an animation that would move, change content and size of Views in the Layout. I am using constraint layout. I have two xml files one for regular layout, one for layout that I need to transition to.
I need to change: Contraints, Text, Tex Size and Visibly of multiple views.
I tried using:
ConstraintLayout rootLayout = (ConstraintLayout) findViewById(R.id.main);
ConstraintSet newConstraint = new ConstraintSet();
newConstraint.load(this, R.layout.activity_selected);
TransitionManager.beginDelayedTransition(rootLayout);
newConstraint.applyTo(rootLayout);
However this doesn't update the text size, as it is not part of the ConstraintLyout class
I also tried using
selectedScene = Scene.getSceneForLayout(sceneRoot, R.layout.activity_selected, this);
TransitionManager.go(selectedScene, set);
But this does not produce a nice animation and required additional complications such as creating up setEnterAction() etc
Is there an elegant way to animate Constraint Layout change while changing text and text size of the views
When using constraint sets, you can only change the constraints of a view and not its properties like the text size, color etc. In order to animate those properties, I would prefer you to use the object animator instead. There you have lots of possibilities.
Related
I have a TableLayout, creating this table:
And I simply want the background color to fill the space given, rather than matching the content (however it does extend horizontally?)
How would I go about doing this? I set the individual TextViews to fill_parent, but that caused errors...
Edit: XML is here:, as it's pretty big
I need to draw custom borders in android to all of the views on my screen. Every view will have different parameters. To do this, I thought about making new CustomBotton, CustomTextView etc. classes and redefine their onDraw() methods. But the methods will contain the same code, so it's not nice to
make new classes for those Views and
rewrite the same onDraw() method with the same code.
Is there a more elegant/faster way to do this?
Do something like this for simple and fast solution (Doing things quick always has a performance trade off).
Dont deal with onDraw for anyview.
Make a single class extending LinearLayout.
2.1 Set Background of this Linearlayout as color of your border.
2.1.1 - More better read border color attribute from xml at runtime.
2.2 Set its padding as width of your border.
2.3 Set its width and height as wrap_content and wrap_content respectively.
Add single view to this LinearLayout. Either programatically or via xml.
<com.example.BorderLinearLayout >
<ImageView /> // or whatever. But a single view or viewgroup only
</com.example.BorderLinearLayout>
Hope this helps
I am developing an android app. There are six main long variables that are displayed on-screen at any time. These are continually incremented using a timer on a separate thread. The user can watch these variables increase on screen. Each of these variables has a maximum amount.
What I'd like to do is draw a 'progress bar' for each of these variables. At the moment, I am using a View with a solid red colour.
Please see below for prototype:
The red bar on the left would represent a variable that has reached it's maximum amount, whilst the others are empty and the bar has a width of 0, so is invisible. Each variable is placed in a RelativeLayout (which represents one 'section'), which is then placed in a LinearLayout. At a future point I may need to add/remove some - so the solution needs to not rely on hard-coded layout positionings.
My question is how can I programmaticaly set the width of these 'progress bar's in code, whilst not hard-coding the layout co-ordinates of any of the variables?
You should check http://developer.android.com/reference/android/widget/ProgressBar.html ProgressBar. It will ease you with displaying the progress.
In the case of LinearLayout (and any ViewGroup for that matter) you can generate your own LayoutParams programatically:
LayoutParams params = new LayoutParams(width,height) // in px
yourLinearLayout.setLayoutParams(params);
you will need to cast the LayoutParams to the according ViewGroup type.
The regular way would be to use the ProgressBar, but if you want to use your custom view, use this:
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(withInPx, heightInPx);
yourView.setLayoutParams(lp);
This assumes you use LinearLayout, but you should edit that if you use a different layout (i.e. RelativeLayout)
The heightInPx will be fixed in your case, but the withInPx you can vary, according to the progress.
Do i need a layout for a view for when the user "paints" on the screen? And what type of layout should i have? Can it be virtually anything? Like a white screen? Thanks.
You need to use at least one layout which will act as your holder View.
It can be a white screen or whatever you want etc.Instead of programming creating all the views make a holder View for your paint stuff and do the painting on it.
No, XML layouts are optional. You can create it programmatically:
View view = new MyCustomPaintView(context);
setContentView(view);
But XML layouts are very usefull (and strictly recommended) when you need to place many Views on a screen.
I'm trying to add a scroll view inside another scroll view.
It should look like is this:
scroll view
linear layout
myprogramaticscroll view
myprogramticlinear layout
myprogramticbutton
end button
end layout
end scroll
end linear
end scroll
I'm trying to add scroll views inside of that. It goes in there, but I need to know how to set parameters correctly so I can see the whole button I have inside of my scroll view. I only see part of it, and I need to set the programatic linear layout and scroll view's width height and id. How do I do this? This is what I have so far:
//the layout I'm putting my scrollview/linearlayout/button in
LinearLayout l = (LinearLayout) findViewById(R.id.linearLayoutFavorites);
ScrollView scroll = new ScrollView(this);
LinearLayout nl = new LinearLayout(this);
ImageButton yourButton = new ImageButton(this);
nl.addView(yourButton);
scroll.addView(nl);
l.addView(scroll);
You CAN'T put a scroll view inside another scroll view, that behavior would be odd, and Android would not know how to handle your scroll on the views.
For setting layout parameters, take a look at ViewGroup.LayoutParams, there're actually quite a few subclasses of ViewGroup.LayoutParams, which are for setting layout parameters for different kinds of layouts.
You can use a Scrollview in an another Scrollview. But this is not suggestible. It will be an issue to both the user and android OS. It will leads to Memory issues and also touch issues while scrolling the views. If you are expecting the Two scrolls (Horizontal and Vertical) at a time, then it is preferble to go for TwoDSCrollView
If you want to set the Layoutparams you should look at ViewGroup.LayoutParams.
If you want to set width and height then no need to set the Layoutparams. You can get the existing params by using getLayoutParams() for the view and set width and height to that params.
If you want to place vertical in vertical scroll or horizontal in horizontal scrollview the you should set the height of the internal scrollview height to the actual height of the total childs.