MotionLayout in AndroidX - android

I want to use MotionLayout but my app is in AndroidX, I have tried using the usual XML tags but they don't work. The Layout Editor just shows a gray box with the tag name. How do I use MotionLayout in AndroidX, or if that is not possible can you give me an alternative.
Thanks :)
It now happened with GridLayout too. Here are the screenshots:
This is just weird.
The code for GridLayout:
<androidx.gridlayout.widget.GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content>
</androidx.gridlayout.widget.GridLayout>

MotionLayout was added to ConstraintLayout 2.0 so make sure that you have
implementation 'androidx.constraintlayout:constraintlayout:$androidConstraintLayoutVersion'
within your app's build.gradle where $androidConstraintLayoutVersion is at least 2.0

hard to say without code,
but make sure that you xml tag is right:
<androidx.constraintlayout.motion.widget.MotionLayout ...>

Related

Android: set all view to visible for testing/ debugging purposes

I was wondering wheather when previewing the layout in Android Studio I can see all view regardless of their visibility in order to inspect all the elements in the preview without changing something in the code (just for debugging purposes).
Thanks in advance!
you can use:
android:visibility="gone"
tools:visibility="visible"
the tools namespace is there for this type of situation where it's only relevant for development.
and then just import:
xmlns:tools="http://schemas.android.com/tools"
in your root layout, if your IDE doesn't suggest it

Android Widget Shadow which supports from API 16

I want to have shadow in Android widget like button, edittext, searchview or anything. I have no idea about android elevation. I think it only supports from API 23. If there is any proper solution then please provide.
here is my demo widget. I need the shadow in border of my searchview.
<android.support.v7.widget.SearchView
android:id="#+id/searchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroud="#android:color/white" />
You can get the shadow effect by adding this to the widget:
android:background="#android:drawable/dialog_holo_light_frame"
Got the answer from here: https://stackoverflow.com/a/30931750/8466860.
Place your views inside CardView. Using CardView you can add elevation, rounded corners etc. It supports back till API 7.
to use CardView, add it via your app level gradle..
dependencies {
...
compile 'com.android.support:cardview-v7:25.3.1'
}

How to convert vertical guideline into Percentage

This looks easy,After adding Vertical Guideline, When you click on the upper arrow it turns into percentage, but there is something wrong in my android studio, or in the constraint layout version i am using or may be i am doing something terribly wrong here.
I have tried everything, but it always shows the same arrorw, and never turns itself to percentage, when i click on it.
I am using Android Studio 2.2, and added this in my gradle.
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
Kindly guide me how to convert this into percentage.
It works in Android Studio 2.3 with
compile 'com.android.support.constraint:constraint-layout:1.0.1'
However, there are a couple of problems with the usage. Sometimes the icon is hidden under other items, making it difficult to click, and at other times clicking on the icon will select something underneath. I have found you sometimes need to zoom in a great deal and then click right in the middle of the icon on the little triangle. One click will reverse the direction of the guideline and two clicks will convert it to percentage.
If that fails you can always change the xml directly. Replace
app:layout_constraintGuide_begin="51dp"
with
app:layout_constraintGuide_percent="0.3611111"
for example.
You could use Percent Support Library
The Percent package provides APIs to support adding and managing
percentage based dimensions in your app.
Add dependency to your Gradle build script, change version depending on your project:
compile 'com.android.support:percent:24.2.1'
In your Layout, you could add a PercentRelativeLayout.
You can specify dimension or a margin of child by using attributes
with "Percent" suffix
For instance:
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="25%"
app:layout_marginLeftPercent="25%"/>
</android.support.percent.PercentRelativeLayout>

Is it possible to scroll a ScrollView with a ConstraintLayout in Blueprint Mode?

So I have been developing this layout using a ConstraintLayout inside a ScrollView. It works fine, but now I have hit a problem. I have to expand the layout outside the screen. I can scroll in Design mode, but I cannot add anything without it getting stuck to the top. The constraints are for earlier objects, not the current one I'm adding.
I can add constraints in Blueprint mode, but it looks like I cannot scroll the ScrollView in blueprint mode. Is this even possible? Using Android Studio 2.2(release) and constraint-layout:1.0.0-alpha8
I tried doing it like in Design mode, but it doesn't scroll. Any ideas?
Scrolling normally with ConstraintLayout causes the constraints to stay in the same location.
EDIT:
Updated to alpha9 but still does not solve it
EDIT 2:
beta1 does not work either. AS 2.2.2.
EDIT 3:
Sample layout:
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/sampleButton"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardcodedText">
<android.support.constraint.ConstraintLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- ETC constraints -->
</android.support.constraint.ConstraintLayout>
</ScrollView>
In android studio 2.2 update, it includes scrolling in design and blueprint mode by default. click on design mode in the preview pane and try to scroll your screen it will start scrolling. There is another option of blueprint in that mode it shows you the blueprint of the design and by doing same for this will help you scroll in blueprint mode also.
Put the Scroll view outside of the Constraint layout. Then use this [Red mark] to drag the view and it will make a custom device editor to you. When you have done, change back to the device editor [Beside rotation icon]...
In latest android studio 2.2.2 version with constraint-layout:1.0.0-beta1 you can scroll blueprint
for better working, after updating constraint-layout please restart android studio (invalidate caches)
Not yet.
Maybe try to have a separate file to edit the content instead, and use an include in the file where you have the ScrollView?
As of ConstraintLayout 1.0.1 scrolling scrolls the constraints. Meaning it is possible to scroll a ConstraintLayout in blueprint mode and it functions as expected. It works at Android Studio 2.3.2 and up (I haven't older versions).
Now when scrolling, both the visible view, the border, and constraints move along with the drawn button.
beta1 version has been released. I doubt this is fixed, but check it out.
You can ask for a bugfix for this here: http://tools.android.com/feedback
PS: you are trying to scroll using the mouse scroll wheel, right? hehe just checking... I say that because just recently I figured out I could scroll in the design mode using the mouse wheel.. duhh haha. I never tried in blueprint mode though.

Android Studio Rendering fragment issue

I am, at the moment, trying to make a google maps app using android studio.
Right now, everything is fine, except for one thing, when i go to the "Design" Tab, in the XML file i have this Redering message:
Rendering Problems A tag allows a layout file to
dynamically include different layouts at runtime. At layout editing
time the specific layout to be used is not known. You can choose which
layout you would like previewed while editing the layout...
And the main problem is that I cannot use any of the gui components in my layout, I searched about my problem and i understood that with this error, people couldn't see their map but they could put on textfields, widgets, layouts, etc.
But for me, my preview is completly frozen and i can't do any modification.
Picture of my android studio page.
As you can change the fragments dynamically with your code, android studio doesn't know which layout to show in design time. This is the reason of your error.
To specifically tell android which layout to show, add tools:layout="#layout/Your_layout_name" attribute to your fragment.
There is also a shortcut link below the error description which you have told. Just click on the link and android will add it for you and you will see the fragment in your layout with no rendering error messages.
For a detailed example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.insane.fragmenttest.MainActivity">
<fragment
android:id="#+id/testFragmentID"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.insane.fragmenttest.WorkOutDetails"
tools:layout="#layout/fragment_work_out_details" /> <!-- This is the line you want to add. -->
</LinearLayout>
Try using Designtime Layout Attributes. http://tools.android.com/tips/layout-designtime-attributes
These attributes guide Android Studio on how to render run-time attributes in the layout editor.
I think you should include tools:showIn="#layout/activity_maps" in your the <fragment> part of your google_maps_api.xml
Just use this design for the fragment. This solved my problem. Also, refer to this link
<fragment
android:id = "#+id/ma"
android:name = "com.google.android.gms.maps.SupportMapFragment"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context = "com.example.demomaps.MapsActivity"
/>
Yes I solved this easily..Simply ignore the message and click line that is showing below of the rendering messages.
Actually fragment contains layout inner and if its not include its showing warning that it must contains you can simply ignore this message below the warning then this rendering issue will be resolved.

Categories

Resources