Want Relative Layout from the beginning - android

Novice in Android Studio. Recently started practising basic coding. I want to have relative layout or linear layout from the beginning. Tried but could not make it possible. Could not find any option provided to select the layout theme. Automatically constraint layout getting launched. Please guide..

Change this line:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
To
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
And do check your ending tag changes to this:
</android.widget.RelativeLayout>
Also (optionally) go ahead and delete this line if it's being shown in grey:
xmlns:app="http://schemas.android.com/apk/res-auto"
And also this is an optional change to make in project,
If the constraint layout is not needed in the project remove the following dependency from build.gradle by deleting this line and then doing gradle sync:
compile 'com.android.support.constraint:constraint-layout:......'

Related

tools:context=".MainActivity" is failing, how can i solve it?

the argument: tools:context=".MainActivity" gives me error, addly the part named: .MainActivity appears in color red, what can i do?
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tried rebuild project or try invalidate cache restart
if still same problem you can add yourpackagename.mainactivity
like in the picture this
tools:context="com.etest.myapplicwr.MainActivity">
my packgae name is com.etest.myapplicwr
replace it with your package name
You can delete it, or you can update it to point to some activity or fragment where you will be using this layout resource.
you should find which folder save your MainActivity.
For Example:
So, Check it.
And then, you should understand what's its function.
it is used by: Lint, Android Studio layout editor .
This attribute declares which activity this layout is associated with by default.
This enables features in the editor or layout preview that require knowledge of the activity, such as what the layout theme should be in the preview and where to insert onClick handlers when you make those from a quickfix.
you can find more information here

How to bring back RelativeLayout?

I am quite familiar with RelativeLayout of Android. However, since I have up updated Android Studio(2.3), ConstraintLayout is set as the default layout of all the new projects.
The problem is:
I am not able to delete the ConstraintLayout.
How can I set it (RelativeLayout) as default so that I don't have to tweak around.
I was able to learn about the tweak around from this answer: How to switch from the default ConstraintLayout to RelativeLayout in Android Studio 2.3.3
Also please provide me any helpful information about ConstraintLayout, ie. why use it over relative layout, tutorial/help text regarding ConstraintLayout so that I can learn it.
To change layout go to your xml code and change your root layout to desired layout, if it shows error, post error message here.
This part is from my other answer:
https://stackoverflow.com/a/42779569/3870382
To change defalut layout when creating an Activity, you can modify default template layout file in Android Studio resources, go to your Android Studio folder and go to following folders path to it:
\plugins\android\lib\templates\activities\common\root\res\layout
Edit file simple.xml.ftl and change layout to your choice, notice that some layouts require additional elements (e. g. LinearLayout needs android:orientation), save file and create activity in Android Studio, you should get an Activity with xml layout that you changed.
Mine looks like this (I had 2.2.3 in that time so I have still RelativeLayout)
(You should see your constrainLayout in this file, so change it to relativeLayout)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<#if hasAppBar && appBarLayoutName??>
xmlns:app="http://schemas.android.com/apk/res-auto"
</#if>
android:id="#+id/${simpleLayoutName}"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
<#if hasAppBar && appBarLayoutName??>
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/${appBarLayoutName}"
</#if>
tools:context="${relativePackage}.${activityClass}">
<#if isNewProject!false>
<TextView
<#if includeCppSupport!false>
android:id="#+id/sample_text"
</#if>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</#if>
</RelativeLayout>
You may have already tried this, but if not. Go to the top menu of your Android Studio with a project open. "Window" tab, Then pull-down to "Store Current Layout as default" and "Restore to default layout". If the default is not what you like, download a layout you would like as default and set it as your default layout.
I pretty much always use RelativeLayout or LinearLayout as well.. Unfortunately I am not versed on ConstraintLayout.
Hope this helps! :)
I am answering this for android studio 2.3.1.
One of the easiest way to set RelativeLayout as main layout instead of the constraint layout is going to text mode and editing the xml file as followed
Change this line
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
To
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
And do check your ending tag changes to this
</android.widget.RelativeLayout>
Also go ahead and delete this line if its being shown in grey.
xmlns:app="http://schemas.android.com/apk/res-auto"
Hope it solves the issue.

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.

Uri is not registered for layout in test resources

I'm new at Android testing and I'm trying to test a custom view in an android library and i'm using Android Studio.
I found here : Android: How to test a custom view? that I should use ActivityUnitTestCase and a mock activity.
I have put my xml layout inside projectname/library/src/androidTest/res/layout and my test activity know my layout R id thanks to this : Configuring res srcDirs for androidTest sourceSet.
My issues is in the layout content.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<eu.custom.customView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
In my case, "http://schemas.android.com/apk/res/android" display in red with an error "URI not registered" and the IDE doe's not recognize my custom view if I add it in this xml.
Is there a way to have this layout working without putting it in production code ?
Thanks
Well, in my Eclipse IDE your code looks correct (there are no red lines) may I suggest you to download the ADT-Bundle again or use Android Studio? I think your IDE is corrupted or something in your settings is wrong. Also check if you have downloaded the up-to-date SDK build tools.

ADT Plugin: Missing properties in layout editor

I'm having trouble with eclipse ADT plugin. Everything was ok in Eclipse's layout editor, in both graphical and XML modes. I designed the GUI mostly from the graphical editor, for convenience.
At some point the Properties view broke. Now it only shows properties for the "View" class, and every other property from View subclasses are not shown (for instance, properties of ImageView are not shown). Properties for aligning inside RelativeLayout are also missing (for instance alignParentTop).
This is a "clean" eclipse install I use only for android, there are no other plugins installed (other than subeclipse). It has never failed me before. I've updated the SDK and also the plugin to the last version but it didn't fix this problem. Eclipse is v3.7 Indigo R2.
Also tried cleaning the project to no avail.
Have you seen this behaviour before? Is it possible to get the graphical editor back and fully working as expected without reinstalling everything again?
Thanks in advance.
UPDATED:
I've traced the problem to a single layout XML. Other layout XMLs are working fine. And the problem is that I'm using the DrawerLayout as main layout:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android">
If I replace this layout for a regular LinearLayout everything returns back to normal. Still I've to find a solution, because every modificattion attempted on the graphical layout results in that element being removed. So this is probably a bug and not only it is inconvenient but also dangerous!
I had the same problem and managed to fix it by splitting the content of the DrawerLayout out into different files like this:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- The main content view -->
<include layout="#layout/activity_tab_content"/>
<!-- The navigation drawer -->
<include layout="#layout/navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
Now I can edit the content of the drawer successfully in a separate editor.

Categories

Resources