I'm using Intellij IDEA 2017.2.2 for Android app development. I have the following layout 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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/image_x"
android:id="#+id/text_x"
android:layout_marginStart="24dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBaseline_toBaselineOf="#+id/edit_image_x" />
...
</android.support.constraint.ConstraintLayout>
However when I open Design tab, I see that value of layout_marginStart is ignored and there is 0 in properties panel. When I try to set margin to other value, editor does not set layout_marginStart to new value, but creates layout_marginLeft what has no effect because there is still layout_marginStart.
This problem appeared after upgrade of Intellij IDEA from 2016.3 to 2017.2.2.
Is it a bug? How can I fix it? I don't want to remove all layout_marginStart from my code and replace it with layout_marginLeft. Is there any other solution?
Related
After updating Android Studio to the latest version if i create a new app and but simple textview to that app the textview goes at the center of the layout instead of the top, i don't know what's wrong please help me.
layout
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_dashboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="My name is john"
android:textSize="20sp"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Go to where you placed your fragment or BottomNavigationView, most of the time it located in activity_main, So remove this android:paddingTop="?attr/actionBarSize" to the parent layout
Using Android studio 3.1, and I have a strange problem, I can't edit my UI,
I enter the content_main.xml, using the design tab, blueprint, anything i drag to the blueprint is not appearing, I use the infer constraints, still not helping
this is my XML code:
<?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:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/app_bar_main">
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="53dp"
tools:layout_editor_absoluteY="168dp" />
</android.support.constraint.ConstraintLayout>
I would't recommand using the UI designer, you don't get the feeling of what you are really doing with it. You should learn how to directly edit the XML file, this isn't really harder and at least you know what you are doing.
You must drag the widget to the component tree
ver imagen
I have a module called TestGUILib and I have specified testview.xml with a simple FrameLayout.
<FrameLayout 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">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Testing View!" />
</FrameLayout>
I tried to use this layout in my main app activity_main. Here is my code:
<?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="com.example.sam.testapp1.MainActivity">
<TextView
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" />
<include layout="#layout/testview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
</android.support.constraint.ConstraintLayout>
Everything works fine. It compiles ok and runs ok. But the preview doesn't work. It shows the blank screen (ie. when I clicked on "Design", it turns blank) with render errors:
Could not find layout resource matching value 0x7F04002F (resolved name: testview) in current configuration.
Also, there is a line under testview (ie. include layout="#layout/testview"). When I rolled my mouse over, it said
Typo in the word 'testview'
Spellchecker inspection helps locate typos and misspelling in your code, comments and literals, and fix them in one click.
Any idea? Thanks
go to "File > Invalidate Caches/Restart...", click "Invalidate and Restart". it should work.
Lets assume you have moduleOne and moduleTwo and if you want to use moduleTwo resources in moduleOne add following (sample) code in moduleOne gradle
dependencies {
compile project(':moduleTwo')
}
This will include moduleOne into you moduleTwo in order to use its resouces including layouts.
Possible you have forgotten to enable
buildFeatures {
viewBinding true
}
in the second module. In that case viewbinding will not find view and show it red like an unknown element
When I add the RecyclerView to the layout, it shows up as a blank screen. Is there a way, such as through the tools namespace, to show a preview of the content of the RecyclerView?
#oRRs is right !
I'm using Android Studio 1.4 RC2 and you can now specify any custom layout.
I tried a custom CardView and it works.
tools:listitem="#android:layout/simple_list_item_checked"
Android tools and LayoutManager
tools namespace enables design-time features (such as which layout to show in a fragment) or compile-time behaviors (such as which shrinking mode to apply to your XML resources)
It is really powerful feature that is developing and allows you not compile code every time to see changes
AndroidX[About] and GridLayoutManager
implementation 'androidx.recyclerview:recyclerview:1.1.0'
<androidx.recyclerview.widget.RecyclerView
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:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
tools:listitem="#layout/item"
tools:itemCount="10"
tools:orientation="vertical"
tools:scrollbars="vertical"
tools:spanCount="3"/>
Support library and LinearLayoutManager
implementation 'com.android.support:recyclerview-v7:28.0.0'
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layoutManager="android.support.v7.widget.LinearLayoutManager"
tools:listitem="#layout/item"
tools:itemCount="3"
tools:orientation="horizontal"
tools:scrollbars="horizontal" />
Another cool feature that was introduced in Android studio 3.0 is predefining a data through the tools attributes, to visualised easily your layout structure using #tools:sample/* resources
item.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="100dp"
android:layout_height="150dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="10dp"
android:orientation="vertical"
tools:background="#tools:sample/backgrounds/scenic">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorWhite"
tools:text="#tools:sample/first_names" />
</FrameLayout>
Simulator results:
First, add the following line in your item XML to made a preview of your list while you edit your item:
tools:showIn="#layout/activity_my_recyclerview_item"
And them, add the following line in your RecyclerView XML to preview how your item will look in your list:
tools:listitem="#layout/adapter_item"
As of Android Studio 1.3.1 it shows default list items in the preview but it doesn't let yout specify your own yet. Hopefully, it will come.
If you have already a custom_item layout:
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
...
...
**tools:listitem="#layout/name_of_your_custom_item_view"**
...>
</androidx.recyclerview.widget.RecyclerView>
I just updated my Android Studio and Android SDK, and now I can't do anything in my XMLs. It shows the same thing as previous, but I can't add anything and something got messed up.
Example:
<?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="horizontal">
<ImageView
android:id="#+id/bocterAppLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/bocterapp"
android:contentDescription=""/>
</LinearLayout>
It error says: "Element ImageView is not allowed here".
Do you have any idea why this has happened?
Cheers!
I had the same problem. Try to exchange the ImageView with the android.support.v7.widget.AppCompatImageView! That solved it for me.
I also had the same problem. In my case, I was using a container from the old support library. So changing
<android.support.constraint.ConstraintLayout ... />
to
<androidx.constraintlayout.widget.ConstraintLayout ... />
solved it for me - with no change to the ImageView.