I am working on CrimeIntent app in Android Programming:
The Big Nerd Ranch Guide. I got a rendering problem when i put an EditText widget in a LinearLayout file for a fragment (fragment_crime.xml).Here is the code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:id="#+id/crime_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/crime_title_hint"/>
</LinearLayout>
I do not want to change the theme.
There is no error in your layout xml... possible it is the plugins and library loading issue in android studio... try to restart it or check the missing libraries and targets.. or check the #string/crime_title_hint if it exists in Strings.xml resources.
Related
When the application is launched, my layout is displayed for a very short second and then disappears. As a beginner in Kotlin, I don't understand why it produces this result.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="univ.master.kotlin.weather.city.CityFragment">
<fragment
android:id="#+id/city_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="univ.master.kotlin.weather.city.CityFragment"/>
</LinearLayout>
It's just a message from the preview window telling you that it can't show a preview for the fragment tag due to not knowing what kind of fragment you'll insert. When you run your actual app, the fragment will render fine.
try to add :
tools:layout="#android:layout/YOUR_LAYOT"
<fragment
android:id="#+id/city_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#android:layout/YOUR_LAYOT"
android:name="univ.master.kotlin.weather.city.CityFragment"/>
Thank you for sharing your xml and java code. If you tried everything and still layout is not appring it is just because of android studio is not able to catch you .xml code not to worry.
You can Select all xml code ctrl+A>ctrl+X>ctrl+V Don't ask me how.
I don't even know how but it works for me. You can also try this because this is the android studio universal rule
Rebuild project or Clear catch and restart
Hope it helps
I am beginner in android studio and having headache with this if someone could help me am i missing something?.... I have problem with Constraint layout, the problem is i put some element(ImageView, Button it does not mater) in layout and constraint it to parent but when I run it in emulator it just is not showing. also it is not showing me those buttons under elements connect BaseLine and remove Constrains for that element.
"screenShot":
<?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">
<ImageView
android:id="#+id/imageView"
android:layout_width="343dp"
android:layout_height="118dp"
android:layout_marginTop="10dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_c`enter code here`onstraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/backgrounds/scenic[7]" />
</android.support.constraint.ConstraintLayout>
when i run it in emulator it just is not showing
The problem is here :
tools:srcCompat="#tools:sample/backgrounds/scenic[7]"
You need to understand what tools is, so I recommend to you to read a little bit the documentation.
Just a note of it :
It's a namespace that enable 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). When you build your app, the build tools remove these attributes so there is no effect on your APK size or runtime behavior.
Instead you have to use to show it on the emulator.
app:srcCompat="#drawable/your_drawable"
Note: remember to add : xmlns:app="http://schemas.android.com/apk/res-auto"
I found the solution.it's difrent in new Android Studio 3.4, You have to Right click on element and option Show Base Line is there now.
I'm currently using VS2013/VS2015 with Xamarin.Android - I'd like to be able to edit layout .axml files with Android intellisense. I use the Automatic editor selector(XML) to edit files. My problem is that while the default Android controls display intellisense fine, as soon as I use a support lib control (like android.support.v7.widget.Toolbar it breaks intellisense for the file (not just the Toolbar control).
For example with the following code, intellisense works fine until I add in the support lib Toolbar:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical"
a:layout_height="wrap_content"
a:layout_width="fill_parent">
<android.support.v7.widget.Toolbar xmlns:local="http://schemas.android.com/apk/res-auto"
a:id="#+id/Routes_Add_SegmentList_Toolbar"
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:minHeight="?attr/actionBarSize"
a:background="?attr/colorPrimary"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<FrameLayout
a:layout_height="wrap_content"
a:layout_width="fill_parent"
a:layout_marginTop="16dp">
<ImageView
a:layout_marginLeft="16dp"
a:scaleType="fitCenter"
a:layout_gravity="left|center_vertical"
a:src="#drawable/start_pin"
a:layout_height="40dp"
a:layout_width="40dp" />
<EditText
a:layout_marginLeft="50dp"
a:layout_marginRight="16dp"
a:id="#+id/Routes_Add_SegmentList_StartSegment"
a:layout_height="wrap_content"
a:layout_width="fill_parent" />
</FrameLayout>
</LinearLayout>
Is there any way to add another xml schema or similar so that it can properly handle non-default android controls? Thanks!
Try
Navigate to root of your solution
Delete .vs folder (hidden folder)
Restart VS
Open solution
Open .axml file
Try and share your thoughts if that works or not.
I'm new to android developing, using eclipse Luna,
When I create my first blank activity project as my book says there should be a layout file (for designing visually the app) in the path"res/layout",
for instance a file named "MyFirstapp.xml" but in my case the layout folder is empty!
I mean there is no where yo see the designing window.
please help me with this problem.
You need to create a new file in the res/layout folder.
Name it e.g. sample_layout.xml
Create a xml based layout or use the graphical interface for it.
Sample code from Android Developers Website:
(http://developer.android.com/guide/topics/ui/declaring-layout.html)
<?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="match_parent"
android:orientation="vertical" >
<TextView android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
<Button android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button" />
</LinearLayout>
Afterwards you can use the layout by calling:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_layout);
}
If you want to get into Android developing please make sure you study Android Developer website:
http://developer.android.com/
There are tons of examples and tutorials!
I'm new to Android development and trying to learn it by the book Android for Absolute Beginners
One of the chapters is about android U.I Design and i'm learning about different android layouts in this chapter .
My problem starts after adding <android.support.v4.widget.SlidingPaneLayout > Tag to my code in order to use android SlidindPaneLayout .
Before Adding this Tag I could use android:layout_width or android:layout_height and ... attribute in all of objects . But now it can be only used inside my sliding layout tag
Here is a little simplified version of my code which as you can see android:layout_width is not used inside Linear Layout because Eclipse doesn't accept it ;)
for more detail look at the link below Please ;)
<?xml version="1.0" encoding="UTF-8"?>
<android.support.v4.widget.SlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="hamid.traingin.hellouniverse.MainActivity"
android:id="#+id/spLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:orientation="horizontal"
android:background="#drawable/milkyway1">
</LinearLayout>
</android.support.v4.widget.SlidingPaneLayout>
Here is a picture of my problem in Eclipse IDE:
The xml code is valid, you can and should add the layout_width and layout_height to you LinearLayout without raising a compiler error. I'm not too sure why Eclipse does not allow you to do so, but Android Studio does: