I want to include a layout of .axml file in another .axml using xamarin android but,
when i use <include> it doesn't show any thing. What is the equivalent to <include> of android in mono android just like the link below:
android reuse layouts
There is no difference between Xamarin.Android (Mono for Android) or native Android's XML files. The axml extension is purely to trigger the code completion in VS and Xamarin Studio. Android does not care what extension the files have.
So let me allow to show a sample showing both the <merge> and <include> tags:
progress_with_text.axml:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:text="Loading..."
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/lblLoading"
android:layout_marginLeft="180dp"
android:layout_marginTop="240dp"/>
<ProgressBar
android:id="#+id/progBar"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="130dp"
android:layout_marginTop="230dp"/>
</merge>
main.axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include
layout="#layout/progress_with_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
This works perfectly fine!
Related
I'm trying to build my first app in Android Studio 4.1.2. I have created a new project (Empty project) with default "Hello world!" Main Activity.
When trying to validate the activity_main.xml I get the following errors:
Error:External resource http://schemas.android.com/apk/res/android is not registered C:\AndroidStudioProjects\MyApp\app\src\main\res\layout\activity_main.xml
Error:(7, 35) cvc-elt.1.a: Cannot find the declaration of element 'androidx.constraintlayout.widget.ConstraintLayout'.
Error:Premature end of file.
I have already tried the following:
Reinstall Android studio
Sync Project with Gradle Files
Invalidate Caches / Restart
build.gradle also has the line implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
I can run the application in emulator or actual device but apparently the validation error prevents me to refer to the layout elements from Kotlin code.
Any ideas how to fix this error?
Here's the activity_main.xml in code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layoutOne"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/textMyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
androidx.constraintlayout.widget.ConstraintLayout
Change this to
RelativeLayout
I have just started android studio, and I can't seem to see the "Hello World" text in my build:
When I switch to another theme I am able to see the text, what could be the problem?
Edit:
The color is not the same as the background.
layout xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textColor="#color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.44" />
</android.support.constraint.ConstraintLayout>
Thank you!
According to the information presented about the problem, you need the closing label of ConstraintLayout
</android.support.constraint.ConstraintLayout>
they stay like this
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textColor="#color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.44" />
</android.support.constraint.ConstraintLayout>
Or you may need to restart the android studio cache
go to the menu file> restat caches / restart
I hope I've helped
This is My Simple Project GUI Interface
My Project
When I run It Its Look Like This
On Run Project
How Can I fix this problem ?
try this,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:textAppearance="#style/TextAppearanceRegular.FontPath" >
<EditText
android:id="#+id/number1"
android:layout_width="match_parent"
android:layout_height="25dip"
android:gravity="start|center_vertical"
android:hint="number1"
android:textSize="16sp" />
<EditText
android:id="#+id/number2"
android:layout_width="match_parent"
android:layout_height="25dip"
android:gravity="start|center_vertical"
android:hint="number2"
android:textSize="16sp" />
<Button
android:id="#+id/plus"
android:text="+"
android:layout_width="100dp"
android:layout_height="50dp"/>
</LinearLayout>
I started using Android Studio 2.2 and ConstraintLayout today, but I'm having some issues with the rendering. When using Blueprint Mode everything appears fine. When using Design Mode, the objects are stuck at the top left corner all mashed together.
Android Studio warning: onMeasure error
java.lang.NoSuchMethodError: android.support.constraint.solver.widgets.ConstraintWidget.immediateConnect(Landroid/support/constraint/solver/widgets/ConstraintAnchor$Type;Landroid/support/constraint/solver/widgets/ConstraintWidget;Landroid/support/constraint/solver/widgets/ConstraintAnchor$Type;II)V
at android.support.constraint.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:517)
at android.support.constraint.ConstraintLayout.updateHierarchy(ConstraintLayout.java:433)
at android.support.constraint.ConstraintLayout.onMeasure_Original(ConstraintLayout.java:728)
at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java)
at android.view.View.measure(View.java:19731)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:19731)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:19731)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:545)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:342)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$72(RenderTask.java:659)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
The dependency:
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
Is this an unsolvable error in Android Studio or is there something that is solvable? SDK is updated.
EDIT
XML file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="#drawable/about"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView6"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="16dp" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView33"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#+id/imageView6"
android:layout_marginLeft="16dp" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView34"
app:layout_constraintRight_toRightOf="#+id/textView33"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/textView33" />
</android.support.constraint.ConstraintLayout>
as mentioned here
Constraint Layout Alpha8 release notes
Note: due to API change, you might have to restart Android Studio 2.2 after upgrading to alpha 8 for layout preview to work.
so From the menu bar, select file and choose invalidate caches / restart
I had that problem after update
implementation 'androidx.constraintlayout:constraintlayout:1.1.3
to
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
downgrade back to 1.1.3 resolve problem
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.yossikally.hello.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<!--<android.support.design.widget.FloatingActionButton-->
<!--android:id="#+id/fab"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="bottom|end"-->
<!--android:layout_margin="#dimen/fab_margin"-->
<!--android:src="#android:drawable/ic_dialog_email" />-->
</android.support.design.widget.CoordinatorLayout>
I built the simplest hello world project.
In the xml design pane I get what's in the picture
Tried to change themes and change version. Get the same
please add to your App gradle file Android Design Support Library:
compile 'com.android.support:design:23.+'